Hi,
Let me start from the beginning...
I'm using a custom database class to access data in a MySQL database (using the MySQL connector). As you will see below, the DBControl.Selec tQuery method returns a dictionary with the column names as keys, and each key's value contains a List<string> of the fields under that column.
I'm loading these values into a ListBox as follows:
Dictionary<stri ng, List<string>> queryResult = DBControl.Selec tQuery("SELECT pkiOperatorID, sOperatorName FROM tOperators");
for (int i = 0; i < queryResult["pkiOperato rID"].Count; i++)
{
listBoxOperator s.Items.Add(que ryResult["sOperatorN ame"][i]);
}
So, the Listbox now contains all the values of the sOperatorName column in the table. That's fine and good, but how do you reference the primary key now? If I have to make a change to the record (for instance, clicking on the name in the ListBox, having it then appear in an InputBox and changing the name there), I obviously have to do an UPDATE sql query. But to do that, I need to be able to know which pkiOperatorID that sOperatorName goes with.
So basically - how can I retain that relationship between the 2 values? (or the key and value, if you will)
Any help would be greatly appreciated!
Let me start from the beginning...
I'm using a custom database class to access data in a MySQL database (using the MySQL connector). As you will see below, the DBControl.Selec tQuery method returns a dictionary with the column names as keys, and each key's value contains a List<string> of the fields under that column.
I'm loading these values into a ListBox as follows:
Dictionary<stri ng, List<string>> queryResult = DBControl.Selec tQuery("SELECT pkiOperatorID, sOperatorName FROM tOperators");
for (int i = 0; i < queryResult["pkiOperato rID"].Count; i++)
{
listBoxOperator s.Items.Add(que ryResult["sOperatorN ame"][i]);
}
So, the Listbox now contains all the values of the sOperatorName column in the table. That's fine and good, but how do you reference the primary key now? If I have to make a change to the record (for instance, clicking on the name in the ListBox, having it then appear in an InputBox and changing the name there), I obviously have to do an UPDATE sql query. But to do that, I need to be able to know which pkiOperatorID that sOperatorName goes with.
So basically - how can I retain that relationship between the 2 values? (or the key and value, if you will)
Any help would be greatly appreciated!
Comment