i have created MS Access Database and it is working fine (ADD, DELETE, Update) now i need to use search function. i need to search using text box and a button. i need to know how to search database using primary key and get those row values in to a text box or list box
I did it like this,
con.Open();
OleDbCommand cmd_ni = new OleDbCommand();
cmd_ni.Connection = con;
cmd_ni.CommandText = "SELECT * FROM Table1 WHERE vehicle_num = @vehicle_num";
cmd_ni.CommandType = CommandType.Text;
cmd_ni.Parameters.Add("id", OleDbType.VarChar);
cmd_ni.Parameters["id"].Value = nu_m;
OleDbDataReader dr1 = cmd_ni.ExecuteReader();
while (dr1.Read())
{
string ni;
ni = dr1["vehicle_num"].ToString();
if (nu_m == ni)
{
Class1.nn = ni;
DialogResult r = MessageBox.Show("the details");
if (r == DialogResult.OK)
{
//here i need the code to select the data row & show it in textbox.
}
}
}
dr1.Close();
con.Close();
after this point i cannot understand what to do. please help me....