hi i have a application,in that when i enter the employee id in textbox,i want to get the data from database,to display it in a some textboxes.like i want to get the pay roll from db into textboxes,that are designation,department,basic salary netamount.it is working,my problem is when i enter the employee id in the textbox also want to display the gridview of a that particular id employee,but am not geting it,i tried it but its not working,please check my code and tell me what should i do?
here is the code...
SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;Data Source=EKTHA-3D34;Initial Catalog=Ektha");
protected void Page_Load(object sender, EventArgs e)
{
txtEmpid.Attributes["onclick"] = "clearTextBox(this.id)";
GridView2.Visible = true;
Label1.Text = Session["UserID"].ToString();
getName();
}
private void getName()
{
// SqlConnection con = new SqlConnection(strcon);
con.Open();
SqlCommand cmd = new SqlCommand("select Name from Admin where UserID ='" + Label1.Text + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
string name = "";
try
{
if (dr.Read())
{
name = dr["Name"].ToString();
lblName.Text = name;
}
dr.Close();
}
catch (Exception ex)
{
string script = "<script>alert('" + ex.Message + "');</script>";
}
finally
{
con.Close();
}
}
protected void txtEmpid_TextChanged(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection(strcon);
con.Open();
SqlCommand com = new SqlCommand("select * from payroll where EmployeeID='" + txtEmpid.Text + " ' ", con);
SqlDataReader dr;
dr = com.ExecuteReader();
if (dr.Read())
{
TextBox24.Text = dr["EmpName"].ToString();
TextBox1.Text = dr["Department"].ToString();
TextBox2.Text = dr["DOJ"].ToString();
TextBox3.Text = dr["BasicSalary"].ToString();
TextBox4.Text = dr["Designation"].ToString();
TextBox5.Text = dr["DOR"].ToString();
TextBox6.Text = dr["NetAmt"].ToString();
GridView2.Visible = false;
GridView3.Visible = true;
}
else
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
}
}
}
manimala