将数据集中的重复行绑定一次

时间:2012-07-28 11:02:25

标签: c# asp.net

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

 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].;


}

两个查询都有一些常见的行。

1 个答案:

答案 0 :(得分:0)

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