0

次のコードを取得しました。

string query = "select * from dbo.Personnel where PersonnelId in ({0})";
string param = "1, 2";
var test = model.ExecuteStoreQuery<Personnel>(query, param).ToList();

次のエラーが表示されます:「nvarchar 値 '1, 2' をデータ型 int に変換中に変換に失敗しました。」...

これを解決する方法を知っている人はいますか?私が欲しいselect * from dbo.Personnel where PersonnelId in (1, 2)のは、数字はどんな数字でもかまいません...

4

1 に答える 1

0

ExecuteStoreQueryパラメータをに送信{0}しないでください。param

string param = "1, 2";
string query = string.Format("select * from dbo.Personnel where PersonnelId in ({0})", param);

また

string query = "select * from dbo.Personnel where PersonnelId in ({0})";
query = query.Replace("{0}",param);

var test = model.ExecuteStoreQuery<Personnel>(query).ToList();
于 2012-11-28T22:04:56.497 に答える