Israel

Israel

  • 693
  • 1.3k
  • 219.4k

Select a combobox's Item when I insert into my textbox

Mar 2 2017 2:47 PM
Hi!
 
I need to make a logic that will select a certain item from my combobox when I insert a value into my textbox. For example, my combobox have three itens (Baby, adult and old) . Then "Baby" is between 0 to 3, "adult" is between 25 to 50 then "old" is between 60 to 90.
Means when I insert into my textbox one of these number its should display on my combobox one of this item.
 
See what I try to do but this is works when I select from combobox display one value into my textbox:
 
string str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\INAC\Documents\Windows_Application_Samples\ComboboxItems_show_in_label\App_Data\office.mdb;Persist Security Info=False";
OleDbConnection con = new OleDbConnection(str);
string query = "select * from tablename where name = '" + comboBox1.SelectedItem.ToString() + "' ";
OleDbCommand cmd = new OleDbCommand(query, con);
OleDbDataReader dbr;
try
{
con.Open();
dbr = cmd.ExecuteReader();
while (dbr.Read())
{
string sname = (string)dbr["name"].ToString(); // name is string value
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
 

Answers (4)