0

私はデータセットを作成しましたが、以下の例のようにIN句 を使用する必要があります

ここに私のクエリがあります:

select field1,field2 from tablename where id **IN** (@ids)  

id パラメータの数は固定ではなく、上記のクエリのたびに変更されます

今、データセットで使用したいと思います。

使い方がわからない

Visual Studio 2010 データセット環境で IN を使用する必要があります。

@ids を 1,2,3,4,... に置き換える方法を知りたいです。

4

2 に答える 2

3

使用できますLINQ to DataTable

var list = new[] { 1, 2, 3, 4, 5 };
var result = dataTable.AsEnumerable()
                      .Where(row => list.Contains(row.Field<int>("Id"));
于 2012-10-31T14:58:27.557 に答える
0

このアプローチを試してください

     public DataSet GetDataSet(string ConnectionString, string SQL)
{
    SqlConnection conn = new SqlConnection(ConnectionString);
    SqlDataAdapter da = new SqlDataAdapter();
    SqlCommand cmd = conn.CreateCommand();
    cmd.CommandText = "YOU SQL QUERY WITH WHERHE";
    da.SelectCommand = cmd;
    DataSet ds = new DataSet();

    conn.Open();
    da.Fill(ds);
    conn.Close();

    return ds;
}
于 2012-11-05T14:46:28.730 に答える