hi
i need to perform a search on a table in the dataset, my code performs the search for the first time only and diplay the result in couple of text boxes placed on the form, but when i try to repeat the search if does not responding at all and nothing happens,
it does not even got stuck..
my code is
string str_search = "SELECT * FROM EMPDETAILS WHERE EMPID= '" + txtItemSearch.Text + "'";
da.SelectCommand = new SqlCommand(str_search, conn);
da.Fill(payRullDataSet, "EmpDetails");
DataTable dt = payRullDataSet.Tables["EmpDetails"];
txtID.Text = dt.Rows[0]["EMPID"].ToString();
this is it ..
any ideas can help ?..:)
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Aug 5, 2009, 10:33 AM EDT
private void SearchButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"); con.Open(); SqlCommand comm = new SqlCommand("select * from Users where Username = '" + txtSearch.Text.Trim() + "'",con); SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { txtUsername.Text = dr["Username"].ToString(); txtPassword.Text = dr["Password"].ToString(); } dr.Close(); con.Close(); }Happy Coding :)
sayed mahdi6 reputationPosted Aug 6, 2009, 12:40 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 1:04 AM EDT
private void SearchButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"); con.Open(); SqlCommand comm = new SqlCommand("Select * from Users where username = '"+textBox1.Text.Trim()+"'", con); SqlDataAdapter da = new SqlDataAdapter(comm); DataSet ds = new DataSet(); da.Fill(ds, "vtable"); con.Close(); string username = ds.Tables[0].Rows[0]["Username"].ToString(); string password = ds.Tables[0].Rows[0]["Password"].ToString(); txtUsername.Text = username; txtPassword.Text = password; } Happy Coding :)