There is a database table TableUser, and there are four fields: FirstName, LastName, Country, State. Actually, there is another field Username, which does not require user to provide, it is ENvironment.Name
When user submits his/her information, first three fields are required, and State is optional.
Now in another form, user wants to update his/her information (It is guaranteed that the user is in database).
Two parts of question:
How to display the record value back into TextBox/ComboBox?
When user updates his/her information, how to write the code to update information in database? It is same that first three fields are required and State is optional.
Thanks.
private void ChildForm1_Load(object sender, EventArgs e)
{
OdbcConnection Cn = new OdbcConnection(GlobalVariables.DatabaseConnectionString);
Cn.Open();
string query = "SELECT * from TableUser WHERE Username = '" + ENvironment.Name + "'";
//It is guaranteed that there is one record
TextboxFirstName.Text = FirstName from returned query; there is a value
TextboxLastName.Text = LastName from returned query; there is a value
ComboBoxCountry.Text = Country from returned query; there is a value
ComboBoxState.Text = State from returned query; It may be missing/null
Cn.Close();
}