比如我要查询 Dataset中 ID 这一列 最大值 存入 int MaxID 中怎么才能查呢?

解决方案 »

  1.   

    DataTable dt=DataSet["表名"];
    select (case when MAX(ID) is null then 0 else MAX(ID ) end) as 最大值 from 表名
      

  2.   

    我说的是在DataSet里面查询哈~~不是在数据库里面查哈
      

  3.   

    ds.Tables[0].Select( "" , "id desc" )[0]["id"]
      

  4.   


    用这个应该就可以拉不用写完整的sql语句的
    请参考
    DataTable table = DataSet1.Tables["Orders"];    // Presuming the DataTable has a column named Date.
        string expression = "Date > '1/1/00'";    // Sort descending by column named CompanyName.
        string sortOrder = "CompanyName DESC";
        DataRow[] foundRows;    // Use the Select method to find all rows matching the filter.
        foundRows = table.Select(expression, sortOrder);    // Print column 0 of each returned row.
        for(int i = 0; i < foundRows.Length; i ++)
        {
            Console.WriteLine(foundRows[i][0]);
        }
      

  5.   

    int MaxID = int.Parse(ds.Tables[0].Select( "" , "id desc" )[0]["id"]);
    id为你的那个要查询的字段名
    注意要是有多个表的话,确保使用了正确的索引