Hi there
I'm looking for a way to add filters in my windows form application. I have a menu strip with item called 'Filters'. Under that items there are items called 'Jobs Pending, Jobs Outstanding, Etc.....'
Take for example 'Jobs Pending'. How do I filter from my database in sql server 2005? My form has a datagridview if that helps.
Here is a sample code I tried, but unsuccessful :(
private void jobsPendingToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
//Opening the sql connection and using custom sql statements
SqlConnection conn = new SqlConnection("Data Source=DEWALD-PC;Initial Catalog=LogbookDatabase;Persist Security Info=True;User ID=sa;Password=123");
String query = "SELECT * FROM " + currentYearLbl.Text + " WHERE " + jobsPendingToolStripMenuItem + " = Pending";
SqlDataAdapter dap = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
dap.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception err)
{
MessageBox.Show("Unable update datagridview" + err);
}
}