Saturday, 14 September 2013

cant get this code to run twice

cant get this code to run twice

private void txtlogin_userid_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//Enter key is down
//Capture the text
if (sender is TextBox)
{
TextBox txb = (TextBox)sender;
dc.SelectCommand = new SqlCommand("select * from
UserMaster where UserID='" + txb.Text + "'", sc);
dc.Fill(ds);
dg.DataSource = ds.Tables[0];
txtlogin_name.Text = ds.Tables[0].Rows[0][1].ToString();
txtlogin_mailid.Text = ds.Tables[0].Rows[0][2].ToString();
sc.Open();
SqlCommand cmd = new SqlCommand("select Location from
UserMaster where UserID='" + txb.Text + "'", sc);
string a = Convert.ToString(cmd.ExecuteScalar());
sc.Close();
string b = "MIND";
if (a.Trim() == b)
{
radiomind.Checked = true;
}
else
{
radioMSSL.Checked = true;
}
}
}
}
this code is fetching me values from database when i just hit enter after
entering the userid.But it does that only once,when i click on refresh
button on the form ,and again enter the userid and hit enter ,it brings me
the same old values instead of new values from the database for the new
userid i enetered. the refresh button has the code "textbox.clear()" for
all textboxes on the form and "radiobtn.clear()" for radio buttons on the
form" please suggest how to solve this.

No comments:

Post a Comment