0

我正在合并两个数据集,我希望重复的行只绑定一次,我该如何实现?

 protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    showRelatedcat();
    DataSet ds = new DataSet();
    DataSet ds_frd = new DataSet();
    String frdQuery = my query
    String newquery = my other query 
    String queryString = another one 
    try
    {
        // Connect to the database and run the query.
        SqlConnection connection = new SqlConnection(connectionString);
        SqlDataAdapter adapter = new SqlDataAdapter(newquery, connection);
        SqlDataAdapter adapter1 = new SqlDataAdapter(frdQuery, connection);
        // Fill the DataSet.
        adapter1.Fill(ds_frd);
        adapter.Fill(ds);
        ds.Merge(ds_frd, true);
        connection.Close();
    }
    catch (Exception ex)
    {

        // The connection failed. Display an error message.
        //Message.Text = "Unable to connect to the database.";

    }



    RadGrid1.DataSource = ds.Tables[0].;


}

两个查询都有一些共同的行。

4

1 回答 1

0

您可以使用 Dataset.Merge 合并数据集,使用 IEnumerable 函数 http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/ebe7e4c2-2cad-4a9d-9134-2732d1e05664 它只允许您获得一个值在重复的情况下

于 2012-07-28T12:00:09.147 回答