Maamun Muhammed

Maamun Muhammed

  • NA
  • 2
  • 1.6k

comboSOrigin.Text = (string)dt.Rows[0]["SOrigin"].ToString()

Jan 24 2016 3:54 AM
I have a "Previous" button on a second form, when i click it, the first Form shows up with the data filled in for some of the controls(textBoxes) but the comboBox looses the data, and has to b re-selected. Please, help me on how the comboBox should displays its selected data too:
 
SqlConnection connection = NasaraCon.GetConnection();
SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM Admission_Table WHERE(AdmNo='" + NasaraCon.admno + "')", connection);
connection.Open();
DataSet ds = new DataSet();
cmd.Fill(ds);
DataTable dt = ds.Tables[0];
//id = (int)dt.Rows[0]["Id"];

if (dt.Rows.Count > 0)
{
labelAdmNo.Text = NasaraCon.admno;
textFName.Text = (string)dt.Rows[0]["FName"].ToString();
textOName.Text = (string)dt.Rows[0]["OName"].ToString();
dateTimeDob.Value = (DateTime)dt.Rows[0]["Dob"];

comboSex.SelectedItem = (string)dt.Rows[0]["Sex"].ToString();
comboLang.Text = (string)dt.Rows[0]["Lang"].ToString();
comboSOrigin.Text = (string)dt.Rows[0]["SOrigin"].ToString();
comboLga.Text = (string)dt.Rows[0]["Lga"].ToString();
textHomeTown.Text = (string)dt.Rows[0]["HTown"].ToString();
textHomeAddr.Text = (string)dt.Rows[0]["HAdd"].ToString();
textDisability.Text = (string)dt.Rows[0]["Dis"].ToString();
}

Answers (1)