hello sir i m facing a problem to searching in datagrid view on selected change on drop down list .
please provide code .
Thnks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjay KumarPosted Mar 9, 2014, 6:06 AM
windows application / web ? try this
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"server = .\sql2012; integrated security = true;
// Select query
string sqlSelect = "SELECT FIRST_NAME,LAST_NAME FROM EmpLogin WHERE EID=" + comboBox1.SelectedIndex + "";
SqlCommand cmd = new SqlCommand(sqlSelect, conn);
try
{
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
txtFirstName.Text = reader[0].ToString();
txtLastName.Text = reader[1].ToString();
}
else
{
MessageBox.Show("This ID does not exist");
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message + ex.StackTrace, "Exception Details");
}
finally
{
conn.Close();
}
}
Rajeev KumarPosted Mar 11, 2014, 1:10 AM
Abhay ShankerPosted Mar 8, 2014, 8:39 PM