retrieve data from a db

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hi,

I have a comboBox and a textbox in my form. I already can display in a
comboBox the department names; what I would like to do is display in a
textbox the department ID related to the department name I chose from
comboBox.


below is the extract of the code:

OleDbCommand myCommand3 = new OleDbCommand();

myCommand3.Parameters["DEPT_NAME"].Value = comboBox2.SelectedItem; --->
THIS LINE GENERATE THE ERROR System.IndexOutOfRangeException

objConnection.Open();
OleDbDataReader objReader3 = myCommand3.ExecuteReader();

objReader3.Read();
textBox4.Text = Convert.ToString(objReader3["DEPT_CODE"]);

objReader3.Close();
objConnection.Close();
 
Select the DEPT_CODE, DEPT_NAME from db as single DataSet, and bind with
comboBox1 like comboBox1.DisplayMemberis DEPT_NAME and comboBox1.ValueMember
is DEPT_CODE.

In comboBox1_SelectedIndexChanged event write the following code,

textBox4.Text = comboBox1.SelectedValue;

Regards,
Amal
 
Back
Top