I'm using Visual Studio 2013, C# and SQL Server database.
The T-SQL command works just fine if I replace the parameter with a concrete value.
I get this error on the last line of code:
Incorrect syntax near '@Collection1'.
My code:
string myCommandString = "select Name, Collection, Text from List_Card @Collection1";
SqlConnection myConnection = new SqlConnection(connectionstring);
SqlCommand myCommand = new SqlCommand(myCommandString, myConnection);
SqlDataAdapter myydata = new SqlDataAdapter();
if (comboBox1.Text != "")
{
string1 = "where Collection IN (select Shortcut from Collections where Collection Like '" + comboBox1.Text + "')";
}
else
{
string1 = "";
}
myCommand.Parameters.Add(new SqlParameter("@Collection1", string1));
myydata.SelectCommand = myCommand;
myConnection.Open();
DataTable myytab = new DataTable();
myydata.Fill(myytab);