Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use both IN and Like Keyword in Sql server command.
here if i wl use accurate TV Radio some text in the input TextBox,then that value is displaying.but i want related like Tv or TVav or TTV like means ,it should display that in gridview

C#
/////////////////////////////
string commaDelimited = textBox1.Text;
string[] year = commaDelimited.Split(new char[] { });
          
/////////////////////////////////////////
//string[] r = { "TV", "Radio", "Coal" };
string filter = string.Empty;
foreach (string name in year)
{
    if (filter.Length > 0)
    {
        filter += ",";
    }
    filter += string.Format("'{0}'", name);
}
SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=ERPDB;Integrated Security=True");
SqlDataAdapter adp;
DataSet ds = new DataSet();
adp = new SqlDataAdapter("Select * from Prod_Tbl where ProductName IN (" + filter + ")", con);
adp.Fill(ds, "Prod_Tbl");
dataGridView1.DataSource = ds.Tables[0].DefaultView;
Posted
Updated 29-Mar-11 3:34am
v2

1 solution

Have you thought of doing some research

http://msdn.microsoft.com/en-us/library/ms179859.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900