First of all i am very embarrassed to be asking because it seems so simple but ive been scouting the forums and just haven't got my head around how this works.
I am trying to populate my list box from a table from SQLite, But i need the actual value to be the id from the database and not the shown value. Now i know there are alot of already answered questions on here but none of the answers ive read seem to work for me.
I am coming over from php programming and it was very simple to do there.
The code i am using is
private void fillTheColours(ListBox colourListBox)
{
colourListBox.Items.Clear();
con.Open();
SQLiteCommand command = new SQLiteCommand(con);
command.CommandText = "SELECT colourId,suffix FROM colours ORDER BY suffix ASC";
command.ExecuteNonQuery();
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
colourListBox.Items.Add(reader["suffix"]);
}
con.Close();
}
That is my function and it works nice to put the visible values into the listbox but that value is useless in the next step of the application.
First of all how would i add the id. Second how would i then access that id ? To set it to a variable ?
Just so its known im using c# in a windows form application in visual studio 2015
Cheers in advance Ryan
Aucun commentaire:
Enregistrer un commentaire