I want to dispaly the data from the datasource based on the type of search the user wants and am not getting any error in the code.. My data grid's name is "Employee_Details", suggest me where am i wrong?
protected void btn_Search_Click(object sender, EventArgs e)
{
string search = list_Search.Text;
string constr = ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString;
SqlConnection myconnection = new SqlConnection(constr);
if(string.Compare(search,"Search By Name",true)==0)
{
try
{
myconnection.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * FROM Emp_Details WHERE Name='" + txt_Name.Text + "'", myconnection);
myReader = myCommand.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(myCommand);
DataTable dt = new DataTable();
//da.Fill(dt);
//DataGrid ds = new DataGrid();
//Employee_Details.DataSource = dt;
while (myReader.Read())
{
da.Fill(dt);
Employee_Details.DataSource = dt;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
myconnection.Close();
}
}
}