-
March 14th, 2009, 07:21 PM
#1
Populate ComboBox from db, Select RecordID
I can populate the drop down list no problem. What I want to do is save the selected data into another table which is related via foreign key. So I want the list to show the text description(Name) but when it is selected I want the EventID to be saved.
Code:
SqlConnection conn = new SqlConnection(@"
server = .\sqlexpress;
integrated security = true;
database = HoopDataSample");
string qryEvents = @"select EventID,Name from Events order by Name";
try
{
conn.Open();
//****Get Event Info to Fill Event Combo Box
SqlCommand cmd = new SqlCommand(qryEvents, conn);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
comboBoxEvents.Items.Add(rdr[1]); //rdr[0] is the EventID,rdr[1] is the Name
}
rdr.Close();
}
Thanks
Last edited by alephNull; March 15th, 2009 at 09:21 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|