For Programmers: Free Programming Magazines  


Home > Archive > C# > November 2004 > ComboBox









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ComboBox
RobRich

2004-11-16, 6:54 pm


I'm having some trouble trying to figure out how to accomplish a task.
Right now I have a combobox that a user
can choose a name out of (the name consists of variables First_Name +
Last_Name). Now after the user has made
their selection and clicks accept. I'd like to somehow reference the
primary key in my database for the person with
that First and Last name.

Here is an example of my code -

private void SelectDriver_Load(object sender, EventArgs e)
{
DriverDatabase ObjDDB = new DriverDatabase();


foreach (DataRow myRow in ObjDDB.tableDrivers.Rows)

{

string First_Name = myRow["First_Name"].ToString();

string Last_Name = myRow["Last_Name"].ToString();

this.driverbox.Items.Add(First_Name + Last_Name);

}

ObjDDB = null;

}



That code populates my ComboBox with the information from my database. Now,
when the user clicks on my 'Accept' button

I'd like to be able to reference the record in the database for which he/she
has selected. I could do a query in the database for

the first and last name, according to the output of combobox.text when the
user hits enter but that wouldn't work because first

and last name are not unique. It might find more then one record or even
the wrong record.



I'm fairly new to programming, so any help would be appreciated.



Thanks



- Rob












Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com