I am using Windows Forms, and I have a combo box with the values:
Apple
Oranges
Pairs
My text box contains values 1, 2 and 3,
apple = 1 and oranges = 2 and pairs = 3.
This relation is in my table on SQL, fields Account and Name. How do I change the value of the textbox to = 2 if the combo box is selected as oranges?
Basically this is reference to a program I'm working on that has an account combo box that displays the accounts names (user friendly). I need the names ID account number to then be displayed in the text box. From this text box I can then pass the value into my stored procedure that will get all the information on that account.
Update
The above text is out of date. See below!
A note to add is that my code gets the account details and populates my combo box.
Is there an easy way to do this? Or does this require joining in C# similar to SQL joins on tables?
Or without using a text box at all, basically my combo would have 2 fields orange, 2 but only display oranges to the user, but my other method uses the second field 2.
OK, so this part adds the acc field to the combo box.
{
SqlCommand accountFill = new SqlCommand("SELECT name, acc FROM dbo.Customer", conn1);
SqlDataReader readacc = accountFill.ExecuteReader();
while (readacc.Read())
{
AddItem(readacc.GetString(0).ToString(), readacc, "name", "acc");
}
conn1.Close();
}
Add item is an invoke method used by my task.
private void AddItem(string value, Object dataSource, string name, string acc)
{
if (accCollection.InvokeRequired)
{
accCollection.Invoke(new Action<string,Object,string,string>(AddItem), new Object[] { value });
}
else
{
//accCollection.Items.Add(value);
accCollection.DataSource = dataSource;
accCollection.DisplayMember = name;
accCollection.ValueMember = acc;
}
}
ERROR complex databinding accepts as a datasource iether an i.list or an i.list source at datasource.