haroldjclements
Freshman
- Joined
- Jun 13, 2004
- Messages
- 46
Hello
This is a quite easy question I hope. I am programming in J# (apologise if this is not the correct forum, I am just seeing if anyone has an idea). I am trying to obtain to fields from a database and deposit them into a comboBox. I have my database setup and retrieving the data. My problem is how I get the data into the comboBox.
An example of the data is the database is:
NameID Name
1 Harold
2 Nick
3 Bob
4 James
When a name is selected the NameID is passed to the next form to retrieve more into on the person.
This is what I have so far.
<CODE>
sql = "SELECT * FROM tblPeople";
OleDbCommand oc = new OleDbCommand(sql, myConnection);
myConnection.Open();
OleDbDataReader dr = oc.ExecuteReader();
while (dr.Read())
{
comboBox1.get_Items().Add(dr.GetString(1) + " (" + dr.GetString(2) + ")");
}
myConnection.Close();
</CODE>
This adds the names to the comboBox but gives me a blank box until I pull the box down. Really I would like something like Select Name and give it the index of 0. I understand that I have not added any indexs in, this is because I am unsure how to.
Any help anyone could give me with this would be very much appreciated.
This is a quite easy question I hope. I am programming in J# (apologise if this is not the correct forum, I am just seeing if anyone has an idea). I am trying to obtain to fields from a database and deposit them into a comboBox. I have my database setup and retrieving the data. My problem is how I get the data into the comboBox.
An example of the data is the database is:
NameID Name
1 Harold
2 Nick
3 Bob
4 James
When a name is selected the NameID is passed to the next form to retrieve more into on the person.
This is what I have so far.
<CODE>
sql = "SELECT * FROM tblPeople";
OleDbCommand oc = new OleDbCommand(sql, myConnection);
myConnection.Open();
OleDbDataReader dr = oc.ExecuteReader();
while (dr.Read())
{
comboBox1.get_Items().Add(dr.GetString(1) + " (" + dr.GetString(2) + ")");
}
myConnection.Close();
</CODE>
This adds the names to the comboBox but gives me a blank box until I pull the box down. Really I would like something like Select Name and give it the index of 0. I understand that I have not added any indexs in, this is because I am unsure how to.
Any help anyone could give me with this would be very much appreciated.