Creating user settings, saving them, and using them with a button click. C#
up vote
0
down vote
favorite
This is my first project on C#, and I'm trying to implement a profile section to my program. I want the user to be able to put in their information, like name, address, ect, and be able to save the information the put in, and use it later on. Right now, I can only have them save one profile, and I'm lost on how to add more profiles with the click of a button. Here is my code currently to save their information:
public void button4_Click(object sender, EventArgs e)
profile1Name = txtProfile1Name.Text;
email = txtEmail.Text;
password = txtPassword.Text;
fullName = txtFullName.Text;
txtEmail.Text = Properties.Settings.Default.Email;
Properties.Settings.Default.ProfileName = txtProfile1Name.Text;
Properties.Settings.Default.Email = txtEmail.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.FullName = txtFullName.Text;
Properties.Settings.Default.Save();
MessageBox.Show($"Profile saved.");
public void LoadSettings()
profile1Name = Properties.Settings.Default.ProfileName;
email = Properties.Settings.Default.Email;
password = Properties.Settings.Default.Password;
fullName = Properties.Settings.Default.FullName;
I have the user input their information into a text box and click save.
I also have another form where users can input information, I'm just not sure how to change the names of the strings that they create.
I'm new to c#, so any other advice would be useful as well.
Thank you in advance for the help :)
c#
|
show 1 more comment
up vote
0
down vote
favorite
This is my first project on C#, and I'm trying to implement a profile section to my program. I want the user to be able to put in their information, like name, address, ect, and be able to save the information the put in, and use it later on. Right now, I can only have them save one profile, and I'm lost on how to add more profiles with the click of a button. Here is my code currently to save their information:
public void button4_Click(object sender, EventArgs e)
profile1Name = txtProfile1Name.Text;
email = txtEmail.Text;
password = txtPassword.Text;
fullName = txtFullName.Text;
txtEmail.Text = Properties.Settings.Default.Email;
Properties.Settings.Default.ProfileName = txtProfile1Name.Text;
Properties.Settings.Default.Email = txtEmail.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.FullName = txtFullName.Text;
Properties.Settings.Default.Save();
MessageBox.Show($"Profile saved.");
public void LoadSettings()
profile1Name = Properties.Settings.Default.ProfileName;
email = Properties.Settings.Default.Email;
password = Properties.Settings.Default.Password;
fullName = Properties.Settings.Default.FullName;
I have the user input their information into a text box and click save.
I also have another form where users can input information, I'm just not sure how to change the names of the strings that they create.
I'm new to c#, so any other advice would be useful as well.
Thank you in advance for the help :)
c#
Have you looked into using the app.config file? Reference
– Symon
Nov 9 at 20:16
4
You are venturing into database land with that requirement.
– LarsTech
Nov 9 at 20:31
@Symon I am using the app.config, I just need to know how to add more.
– Caden Buckelew
Nov 9 at 20:45
@LarsTech Is there a place you could point me in the right direction to learn about databases and for my particular need?
– Caden Buckelew
Nov 9 at 20:46
That is too broad of a question for this site. It's pretty simple to google examples. When you get stuck, ask another question and post the code you are using that is giving you trouble.
– LarsTech
Nov 9 at 20:47
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my first project on C#, and I'm trying to implement a profile section to my program. I want the user to be able to put in their information, like name, address, ect, and be able to save the information the put in, and use it later on. Right now, I can only have them save one profile, and I'm lost on how to add more profiles with the click of a button. Here is my code currently to save their information:
public void button4_Click(object sender, EventArgs e)
profile1Name = txtProfile1Name.Text;
email = txtEmail.Text;
password = txtPassword.Text;
fullName = txtFullName.Text;
txtEmail.Text = Properties.Settings.Default.Email;
Properties.Settings.Default.ProfileName = txtProfile1Name.Text;
Properties.Settings.Default.Email = txtEmail.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.FullName = txtFullName.Text;
Properties.Settings.Default.Save();
MessageBox.Show($"Profile saved.");
public void LoadSettings()
profile1Name = Properties.Settings.Default.ProfileName;
email = Properties.Settings.Default.Email;
password = Properties.Settings.Default.Password;
fullName = Properties.Settings.Default.FullName;
I have the user input their information into a text box and click save.
I also have another form where users can input information, I'm just not sure how to change the names of the strings that they create.
I'm new to c#, so any other advice would be useful as well.
Thank you in advance for the help :)
c#
This is my first project on C#, and I'm trying to implement a profile section to my program. I want the user to be able to put in their information, like name, address, ect, and be able to save the information the put in, and use it later on. Right now, I can only have them save one profile, and I'm lost on how to add more profiles with the click of a button. Here is my code currently to save their information:
public void button4_Click(object sender, EventArgs e)
profile1Name = txtProfile1Name.Text;
email = txtEmail.Text;
password = txtPassword.Text;
fullName = txtFullName.Text;
txtEmail.Text = Properties.Settings.Default.Email;
Properties.Settings.Default.ProfileName = txtProfile1Name.Text;
Properties.Settings.Default.Email = txtEmail.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.FullName = txtFullName.Text;
Properties.Settings.Default.Save();
MessageBox.Show($"Profile saved.");
public void LoadSettings()
profile1Name = Properties.Settings.Default.ProfileName;
email = Properties.Settings.Default.Email;
password = Properties.Settings.Default.Password;
fullName = Properties.Settings.Default.FullName;
I have the user input their information into a text box and click save.
I also have another form where users can input information, I'm just not sure how to change the names of the strings that they create.
I'm new to c#, so any other advice would be useful as well.
Thank you in advance for the help :)
c#
c#
edited Nov 9 at 20:16
asked Nov 9 at 19:19
Caden Buckelew
186
186
Have you looked into using the app.config file? Reference
– Symon
Nov 9 at 20:16
4
You are venturing into database land with that requirement.
– LarsTech
Nov 9 at 20:31
@Symon I am using the app.config, I just need to know how to add more.
– Caden Buckelew
Nov 9 at 20:45
@LarsTech Is there a place you could point me in the right direction to learn about databases and for my particular need?
– Caden Buckelew
Nov 9 at 20:46
That is too broad of a question for this site. It's pretty simple to google examples. When you get stuck, ask another question and post the code you are using that is giving you trouble.
– LarsTech
Nov 9 at 20:47
|
show 1 more comment
Have you looked into using the app.config file? Reference
– Symon
Nov 9 at 20:16
4
You are venturing into database land with that requirement.
– LarsTech
Nov 9 at 20:31
@Symon I am using the app.config, I just need to know how to add more.
– Caden Buckelew
Nov 9 at 20:45
@LarsTech Is there a place you could point me in the right direction to learn about databases and for my particular need?
– Caden Buckelew
Nov 9 at 20:46
That is too broad of a question for this site. It's pretty simple to google examples. When you get stuck, ask another question and post the code you are using that is giving you trouble.
– LarsTech
Nov 9 at 20:47
Have you looked into using the app.config file? Reference
– Symon
Nov 9 at 20:16
Have you looked into using the app.config file? Reference
– Symon
Nov 9 at 20:16
4
4
You are venturing into database land with that requirement.
– LarsTech
Nov 9 at 20:31
You are venturing into database land with that requirement.
– LarsTech
Nov 9 at 20:31
@Symon I am using the app.config, I just need to know how to add more.
– Caden Buckelew
Nov 9 at 20:45
@Symon I am using the app.config, I just need to know how to add more.
– Caden Buckelew
Nov 9 at 20:45
@LarsTech Is there a place you could point me in the right direction to learn about databases and for my particular need?
– Caden Buckelew
Nov 9 at 20:46
@LarsTech Is there a place you could point me in the right direction to learn about databases and for my particular need?
– Caden Buckelew
Nov 9 at 20:46
That is too broad of a question for this site. It's pretty simple to google examples. When you get stuck, ask another question and post the code you are using that is giving you trouble.
– LarsTech
Nov 9 at 20:47
That is too broad of a question for this site. It's pretty simple to google examples. When you get stuck, ask another question and post the code you are using that is giving you trouble.
– LarsTech
Nov 9 at 20:47
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
It is a broad topic, but I believe I can still give you an idea for you to know how it works or at least "What all to google!"
Saving a user information into the properties is not the conventional way of "storing the user information". You will need to add an external database in order to store and retrieve multiple user information.
In order to add an external database, You will have to create a table consisting of fields that will store Username, Password, Age etc. you have options for what database you are using eg: Microsoft Access, SQL, Oracle.
Lets say you are creating a database using Microsoft Access, Firstly you will have to create and open a new MS Access File, Click on the Create Tab and select Table. Add the required fields(Full name, username, email, password In your case) as shown below:
Further, You will need to link your database to the app, for this you will need to:
- Import OLEdb library that handles database manipulation commands
- Code on the button that creates a new profile
- Create a connection string for your database and your app (Connection strings tell the app where your database is located)
- Finally add SQL query that will add user information to the database.
Which will look something like this:
Imports System.Data.OleDb //Preferably placed before the form load code ie. Top of the page
Dim connection As OleDbConnection = New OleDbConnection //Code below, including this is written in the "create profile" button block
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "LoginDB.accdb" //Here, LoginDB is the name of your MS Access file.
connection.Open()
Dim updatequery As OleDbCommand = New OleDbCommand("INSERT INTO LoginTable (FullName,ProfileName,Email,Password) VALUES(@name1,@name2,@email,@pass)", connection) //LoginTable being the name of the table created inside MS Access file.
updatequery.Parameters.Add("@name1", OleDbType.VarChar).Value = TextBox1.Text
updatequery.Parameters.Add("@name2", OleDbType.VarChar).Value = TextBox2.Text
updatequery.Parameters.Add("@email", OleDbType.Numeric).Value = TextBox3.Text
updatequery.Parameters.Add("@pass", OleDbType.Numeric).Value = TextBox4.Text
updatequery.ExecuteNonQuery()
connection.Close()
About Saving information on the properties page of the application, Think of it as more like having one admin profile in properties that can be accessed throughout the app even when the external user database is deleted
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It is a broad topic, but I believe I can still give you an idea for you to know how it works or at least "What all to google!"
Saving a user information into the properties is not the conventional way of "storing the user information". You will need to add an external database in order to store and retrieve multiple user information.
In order to add an external database, You will have to create a table consisting of fields that will store Username, Password, Age etc. you have options for what database you are using eg: Microsoft Access, SQL, Oracle.
Lets say you are creating a database using Microsoft Access, Firstly you will have to create and open a new MS Access File, Click on the Create Tab and select Table. Add the required fields(Full name, username, email, password In your case) as shown below:
Further, You will need to link your database to the app, for this you will need to:
- Import OLEdb library that handles database manipulation commands
- Code on the button that creates a new profile
- Create a connection string for your database and your app (Connection strings tell the app where your database is located)
- Finally add SQL query that will add user information to the database.
Which will look something like this:
Imports System.Data.OleDb //Preferably placed before the form load code ie. Top of the page
Dim connection As OleDbConnection = New OleDbConnection //Code below, including this is written in the "create profile" button block
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "LoginDB.accdb" //Here, LoginDB is the name of your MS Access file.
connection.Open()
Dim updatequery As OleDbCommand = New OleDbCommand("INSERT INTO LoginTable (FullName,ProfileName,Email,Password) VALUES(@name1,@name2,@email,@pass)", connection) //LoginTable being the name of the table created inside MS Access file.
updatequery.Parameters.Add("@name1", OleDbType.VarChar).Value = TextBox1.Text
updatequery.Parameters.Add("@name2", OleDbType.VarChar).Value = TextBox2.Text
updatequery.Parameters.Add("@email", OleDbType.Numeric).Value = TextBox3.Text
updatequery.Parameters.Add("@pass", OleDbType.Numeric).Value = TextBox4.Text
updatequery.ExecuteNonQuery()
connection.Close()
About Saving information on the properties page of the application, Think of it as more like having one admin profile in properties that can be accessed throughout the app even when the external user database is deleted
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
add a comment |
up vote
0
down vote
It is a broad topic, but I believe I can still give you an idea for you to know how it works or at least "What all to google!"
Saving a user information into the properties is not the conventional way of "storing the user information". You will need to add an external database in order to store and retrieve multiple user information.
In order to add an external database, You will have to create a table consisting of fields that will store Username, Password, Age etc. you have options for what database you are using eg: Microsoft Access, SQL, Oracle.
Lets say you are creating a database using Microsoft Access, Firstly you will have to create and open a new MS Access File, Click on the Create Tab and select Table. Add the required fields(Full name, username, email, password In your case) as shown below:
Further, You will need to link your database to the app, for this you will need to:
- Import OLEdb library that handles database manipulation commands
- Code on the button that creates a new profile
- Create a connection string for your database and your app (Connection strings tell the app where your database is located)
- Finally add SQL query that will add user information to the database.
Which will look something like this:
Imports System.Data.OleDb //Preferably placed before the form load code ie. Top of the page
Dim connection As OleDbConnection = New OleDbConnection //Code below, including this is written in the "create profile" button block
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "LoginDB.accdb" //Here, LoginDB is the name of your MS Access file.
connection.Open()
Dim updatequery As OleDbCommand = New OleDbCommand("INSERT INTO LoginTable (FullName,ProfileName,Email,Password) VALUES(@name1,@name2,@email,@pass)", connection) //LoginTable being the name of the table created inside MS Access file.
updatequery.Parameters.Add("@name1", OleDbType.VarChar).Value = TextBox1.Text
updatequery.Parameters.Add("@name2", OleDbType.VarChar).Value = TextBox2.Text
updatequery.Parameters.Add("@email", OleDbType.Numeric).Value = TextBox3.Text
updatequery.Parameters.Add("@pass", OleDbType.Numeric).Value = TextBox4.Text
updatequery.ExecuteNonQuery()
connection.Close()
About Saving information on the properties page of the application, Think of it as more like having one admin profile in properties that can be accessed throughout the app even when the external user database is deleted
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
add a comment |
up vote
0
down vote
up vote
0
down vote
It is a broad topic, but I believe I can still give you an idea for you to know how it works or at least "What all to google!"
Saving a user information into the properties is not the conventional way of "storing the user information". You will need to add an external database in order to store and retrieve multiple user information.
In order to add an external database, You will have to create a table consisting of fields that will store Username, Password, Age etc. you have options for what database you are using eg: Microsoft Access, SQL, Oracle.
Lets say you are creating a database using Microsoft Access, Firstly you will have to create and open a new MS Access File, Click on the Create Tab and select Table. Add the required fields(Full name, username, email, password In your case) as shown below:
Further, You will need to link your database to the app, for this you will need to:
- Import OLEdb library that handles database manipulation commands
- Code on the button that creates a new profile
- Create a connection string for your database and your app (Connection strings tell the app where your database is located)
- Finally add SQL query that will add user information to the database.
Which will look something like this:
Imports System.Data.OleDb //Preferably placed before the form load code ie. Top of the page
Dim connection As OleDbConnection = New OleDbConnection //Code below, including this is written in the "create profile" button block
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "LoginDB.accdb" //Here, LoginDB is the name of your MS Access file.
connection.Open()
Dim updatequery As OleDbCommand = New OleDbCommand("INSERT INTO LoginTable (FullName,ProfileName,Email,Password) VALUES(@name1,@name2,@email,@pass)", connection) //LoginTable being the name of the table created inside MS Access file.
updatequery.Parameters.Add("@name1", OleDbType.VarChar).Value = TextBox1.Text
updatequery.Parameters.Add("@name2", OleDbType.VarChar).Value = TextBox2.Text
updatequery.Parameters.Add("@email", OleDbType.Numeric).Value = TextBox3.Text
updatequery.Parameters.Add("@pass", OleDbType.Numeric).Value = TextBox4.Text
updatequery.ExecuteNonQuery()
connection.Close()
About Saving information on the properties page of the application, Think of it as more like having one admin profile in properties that can be accessed throughout the app even when the external user database is deleted
It is a broad topic, but I believe I can still give you an idea for you to know how it works or at least "What all to google!"
Saving a user information into the properties is not the conventional way of "storing the user information". You will need to add an external database in order to store and retrieve multiple user information.
In order to add an external database, You will have to create a table consisting of fields that will store Username, Password, Age etc. you have options for what database you are using eg: Microsoft Access, SQL, Oracle.
Lets say you are creating a database using Microsoft Access, Firstly you will have to create and open a new MS Access File, Click on the Create Tab and select Table. Add the required fields(Full name, username, email, password In your case) as shown below:
Further, You will need to link your database to the app, for this you will need to:
- Import OLEdb library that handles database manipulation commands
- Code on the button that creates a new profile
- Create a connection string for your database and your app (Connection strings tell the app where your database is located)
- Finally add SQL query that will add user information to the database.
Which will look something like this:
Imports System.Data.OleDb //Preferably placed before the form load code ie. Top of the page
Dim connection As OleDbConnection = New OleDbConnection //Code below, including this is written in the "create profile" button block
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "LoginDB.accdb" //Here, LoginDB is the name of your MS Access file.
connection.Open()
Dim updatequery As OleDbCommand = New OleDbCommand("INSERT INTO LoginTable (FullName,ProfileName,Email,Password) VALUES(@name1,@name2,@email,@pass)", connection) //LoginTable being the name of the table created inside MS Access file.
updatequery.Parameters.Add("@name1", OleDbType.VarChar).Value = TextBox1.Text
updatequery.Parameters.Add("@name2", OleDbType.VarChar).Value = TextBox2.Text
updatequery.Parameters.Add("@email", OleDbType.Numeric).Value = TextBox3.Text
updatequery.Parameters.Add("@pass", OleDbType.Numeric).Value = TextBox4.Text
updatequery.ExecuteNonQuery()
connection.Close()
About Saving information on the properties page of the application, Think of it as more like having one admin profile in properties that can be accessed throughout the app even when the external user database is deleted
edited Nov 9 at 21:19
answered Nov 9 at 21:09
asiffarhankhan
196
196
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
add a comment |
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
Will doing this store their information local to their computer?
– Caden Buckelew
Nov 9 at 21:35
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
I believe the database should be binded with the exe of the app. so whoever has the app also has the database. My app was more about a college model. like a prototype. so worked out for me. I f you are going to share the app, I believe you have to store on online databases such as SQL
– asiffarhankhan
Nov 11 at 20:55
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232052%2fcreating-user-settings-saving-them-and-using-them-with-a-button-click-c-sharp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you looked into using the app.config file? Reference
– Symon
Nov 9 at 20:16
4
You are venturing into database land with that requirement.
– LarsTech
Nov 9 at 20:31
@Symon I am using the app.config, I just need to know how to add more.
– Caden Buckelew
Nov 9 at 20:45
@LarsTech Is there a place you could point me in the right direction to learn about databases and for my particular need?
– Caden Buckelew
Nov 9 at 20:46
That is too broad of a question for this site. It's pretty simple to google examples. When you get stuck, ask another question and post the code you are using that is giving you trouble.
– LarsTech
Nov 9 at 20:47