I am attempting to make my datagridview3 populate with the results of the following code and query but when I click the button to run the code the datagrid view stays blank. Is there anything I am missing?
private void filter()
{
string Query2 = "Select * " +
"From Child " +
"WHERE @Value like '@Textbox'";
SqlConnection con2 = new SqlConnection("Data Source=LT-SDGFLD-1803;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=");
SqlCommand cmd2 = new SqlCommand(Query2 , con2);
try
{
cmd2.Parameters.Add("@Value", System.Data.SqlDbType.VarChar);
cmd2.Parameters.Add("@Textbox", System.Data.SqlDbType.VarChar);
cmd2.Parameters["@Value"].Value = Properties.Settings.Default.ComboBox;
cmd2.Parameters["@Textbox"].Value = Properties.Settings.Default.TextBox;
con2.Open();
SqlDataAdapter da2 = new SqlDataAdapter();
da2.SelectCommand = cmd2;
DataTable dt2 = new DataTable();
da2.Fill(dt2);
dataGridView3.DataSource = dt2;
dataGridView3.Update();
dataGridView3.Refresh();
con2.Close();
}
catch (Exception ec)
{
MessageBox.Show(ec.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView3.DataSource = "LT-SDGFLD-1803";
dataGridView3.Refresh();
filter();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Properties.Settings.Default.ComboBox = comboBox1.SelectedText.ToString();
Properties.Settings.Default.Save();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.TextBox = textBox1.Text.ToString();
Properties.Settings.Default.Save();
}