(DataSet里就一张表)主要目的是想将DataSet中的表上的数据做SQL的查询处理
不知道是否直接就有方法... 如果没有的话想先把DataSet的数据导到SQL上的一个临时表中(按照DataSet中的表结构建,最好连数据也直接过去)
然后执行SQL得到结果

解决方案 »

  1.   

    用DataSet的table,即datatable,它有个Select的方法,可以做过虑
    private static void GetRowsByFilter()
    {
        
        DataTable customerTable = new DataTable( "Customers" );
        // Add columns
        customerTable.Columns.Add( "id", typeof(int) );
        customerTable.Columns.Add( "name", typeof(string) );    // Set PrimaryKey
        customerTable.Columns[ "id" ].Unique = true;
        customerTable.PrimaryKey = new DataColumn[] { customerTable.Columns["id"] };    // Add ten rows
        for( int id=1; id<=10; id++ )
        {
            customerTable.Rows.Add( 
                new object[] { id, string.Format("customer{0}", id) } );
        }
        customerTable.AcceptChanges();    // Add another ten rows
        for( int id=11; id<=20; id++ )
        {
            customerTable.Rows.Add( 
                new object[] { id, string.Format("customer{0}", id) } );
        }    string strExpr;
        string strSort;
        
        strExpr = "id > 5";
        // Sort descending by column named CompanyName.
        strSort = "name DESC";
        // Use the Select method to find all rows matching the filter.
        DataRow[] foundRows = 
            customerTable.Select( strExpr, strSort, DataViewRowState.Added );
        
        PrintRows( foundRows, "filtered rows" );    foundRows = customerTable.Select();
        PrintRows( foundRows, "all rows" );
    }private static void PrintRows( DataRow[] rows, string label )
    {
        Console.WriteLine( "\n{0}", label );
        if( rows.Length <= 0 )
        {
            Console.WriteLine( "no rows found" );
            return;
        }
        foreach( DataRow r in rows )
        {
            foreach( DataColumn c in r.Table.Columns )
            {
                Console.Write( "\t {0}", r[c] );
            }
            Console.WriteLine();
        }
    }
      

  2.   

    ds.Tables[0].Select("QuestionID="+strQuestionID+"");
      

  3.   

    谢谢singlepine(小山)的方法不过这方法对跟我的想法可能有点出入,虽然可能是能实现我的需求我做的是 先用select sum(a) as aa , min(b+c) as cc , max(d) as dd from .....
    之类的语句从多个数据库中分别取得结果
    然后将结果合并放在一个表AAA里
    再执行一遍类似于select sum(aa), b , min(cc) , max(dd) from AAA 的语句来获得最终结果
      

  4.   

    建议使用sqlDmo
    C#中使用SQL Server分布式管理对象(SQL-DMO)
    http://dotnet.aspx.cc/ShowDetail.aspx?id=BCEAADFB-CFF3-4804-B3B3-6C7D6488982B
    INF: How to Enumerate Available SQL Servers Using SQLDMO
    http://support.microsoft.com/default.aspx?scid=287737