Hello all ,
In my winform application , i need to filter my datagridview based on my text box text , but as i am using like keyword for matching " the values "Accepted" & "Accepted on deviation" are considered as same , hence if i type accepted both of these values are populating(but if i type "Accepted on deviation" it is getting filtered as desired), i tried changing my query but every time i am getting syntax error , kindly help me how to over come this.
i need to filter only columns with "Accepted" when i type "Accepted" instead of getting both the values "Accepted" & "Accepted on deviation"
here is my code:
private void Btnentryview_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.Text.Trim()))
{
Refreshdata();
return;
}
string strkeyword = textBox2.Text.Trim().ToString();
StringBuilder sb = new StringBuilder();
if (textBox2.Text == "Accepted")
{
sb.AppendFormat("(Convert(SpoolID,'System.String') LIKE '" + "{0}" + "')", strkeyword);
sb.AppendFormat("OR (Status LIKE '*" + "{0}" + "*')", strkeyword);
}
if (textBox2.Text == "Accepted On Deviation")
{
sb.AppendFormat("(Convert(SpoolID,'System.String') LIKE '" + "{0}" + "')", strkeyword);
sb.AppendFormat("OR (Status LIKE '*" + "{0}" + "*')", strkeyword);
}
if (textBox2.Text == "Rejected")
{
sb.AppendFormat("(Convert(SpoolID,'System.String') LIKE '" + "{0}" + "')", strkeyword);
sb.AppendFormat("OR (Status LIKE '*" + "{0}" + "*')", strkeyword);
}
if (textBox2.Text == "Rework")
{
sb.AppendFormat("(Convert(SpoolID,'System.String') LIKE '" + "{0}" + "')", strkeyword);
sb.AppendFormat("OR (Status LIKE '*" + "{0}" + "*')", strkeyword);
}
if (textBox2.Text == "All")
{
Refreshdata();
}
string strFilter = sb.ToString();
iP_SpoolsBindingSource.Filter = strFilter;
if (iP_SpoolsBindingSource.Count != 0)
{
iP_SpoolsDataGridView.DataSource = iP_SpoolsBindingSource;
}
else
{
MessageBox.Show("No Records Found", "Search Result", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
Refreshdata();
return;
}
}