hello sir i m facing a problem to searching in datagrid view on selected change on drop down list .
please provide code .
Thnks
Searching in datagridview
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjay KumarRank #561 · 4.3K reputationPosted Mar 9, 2014, 1:06 AM EST
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();
}
}
Abhay ShankerRank #375 · 6.7K reputationPosted Mar 8, 2014, 3:39 PM EST
Rajeev KumarRank #1,937 · 758 reputationPosted Mar 10, 2014, 9:10 PM EDT