Passing items From DataTable to SQL Where Clause c#
<p>I have a single column Datatable, I want to pass this datatable in SQL where clause using sqlparametercollection. Please help.
below is my code:</p>

<pre><code>public DataTable getCatsByDepts(DataTable _Depts)
    {

        SqlConnection conn = new SqlConnection("Server=ax12d;Database=DemoDataAx;Trusted_Connection=True;");
        SqlCommand cmd = new SqlCommand("Select Level2 as Category from Mtq_RetailHierarchy Where Level1 IN (@Depts)", conn);
        foreach (DataRow row in _Depts.Rows)
        {
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("Department", row.Field&lt;string&gt;("Department"));
            //cmd.ExecuteNonQuery();
        }


        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable SelectedCatsData = new DataTable();
        da.Fill(SelectedCatsData);
        return SelectedCatsData;

    }`
</code></pre>
