私はVisual Studio 2013、C#およびSQL Serverデータベースを使用しています。パラメータの近くに不適切な構文
T-SQLコマンドは、パラメータを具体的な値に置き換えてもうまく動作します。
私は、コードの最後の行に、このエラーが出ます: 'Collection1 @'
付近に正しくない構文。
マイコード:
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);
これで間違いなく無効な構文 '文字列、何を達成しようとしています' '@ Collection1'をテーブル名の後ろに置いていますか? –
T-SQLはデータベースエンジンではありません – Plutonix
@Collectionに 'where'句があります。ユーザーがcomboBoxで何かを選択した場合、私は 'where'節が必要です。ユーザーがコンボボックスで何も選択しなかった場合は、「where」節は必要ありません。 – Matthew