如题。在选择语句中可以写成"select * from table1 where id=@id"。之后将@id换成实际的类型,比如uniqueidentifier.要问的是在DataTable.Select中可以这样用吗?即DataTable.Select(“id=@id”),如何把@id换成sqlparameter类型的参数呢。

解决方案 »

  1.   

    似乎不行,DataTable 是与具体数据库无关的,
    而 @Param 这种命名是 SQL Server 特有的参数命名方式可以直接连接字符string filter = "id=" + myIdValue;
    DataRow[] rows = DataTable.Select(filter);
      

  2.   

    DataTable.Select不支持参数的,因为DataTable.Select只是在dataTable中进行筛选,而不是到数据库select。只能这样用:string id = 1;DataTable.Select("id=" + id.ToString());
      

  3.   

    你可以这样变通一下嘛
    string filterStr = "select * from table1 where id= {0}";然后在调用的地方这样
    DataRow[] rows = DataTable.Select(string.Format(filterStr,真实ID值));
      

  4.   

    自己组合 sql  语句就ok了阿