i want to display employee record if employee record is exist when i enter employee id in textbox. when i enter employee id in textbox and it exist in database then employee record should be display in textboxes and required controls like emp name, emp address emp gender, emp mobileno.
i have try to do this but there is no result. its not return any result or action.
SqlConnection con = new SqlConnection(sqlcon);
con.Open();
string sqlSelect = "SELECT empname,empaddress, empcity,empgender,empage FROM empmaster WHERE empid LIKE'"+ txtSearch.Text +"'%'";
SqlCommand cmd = new SqlCommand(sqlSelect, con);
SqlDataReader sdr = cmd.ExecuteReader();
while (dataRead.Read())
{
string vname = dataRead["empname"].ToString();
string[] str = vname.Split(' ');
for (int n = 0; n < str.Length; n++)
{
txtfname.Text = str[0];
txtmname.Text = str[1];
txtlname.Text = str[2];
}
txtaddress.Text = dataRead.GetValue(1).ToString();
txtcity.Text = dataRead.GetValue(2).ToString();
dropgender.Text = dataRead.GetValue(6).ToString();
dropidtype.Text = dataRead.GetValue(7).ToString();
txtage.Text = dataRead.GetValue(9).ToString();
}
con.Close();
error is
ErrorSystem.IndexOutOfRangeException: Index was outside the bounds of the array.