私は識別子で構成される文字列配列を持っています。私は、これらの識別子を使用してSQLからいくつかの値を取得したい。文字列の値をSqlCommand
のパラメータに追加する方法はありますか?SQLクエリに文字列配列を追加する
私のようなクエリを作成したい:
select CaseList from MasterReportData where Id = 1 OR Id = 2 OR Id = 3
これは私のC#のコードです:
public static List<string> GetCaseList(string[] masterIdList)
{
try
{
string query = " select CaseList from MasterReportData where @masterId";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("masterId", ***);
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
list.Add(reader[0].ToString());
}
}
conn.Close();
}
catch (Exception e)
{
var err= 0;
}
return list;
}
可能な重複しているC#の
作成でテーブルを作成します。 [ループ内のSQLパラメータ](https://stackoverflow.c)/QS/24561055/sql-parameters-in-a-loop) –
[SqlCommandで渡すパラメーター](https://stackoverflow.com/questions/2377506/pass-array-parameter-in-sqlcommand) –
@ RufusLはい私は欲しい、またはオペレーター、私は編集した。 – MsK