0

我有这两张桌子

表一
代码标题

KANT-015 如何建立品牌

KANT-016 避免劳动力危机

KANT-017 创建成功的社交媒体策略

KANT-028 准备领导

KANT-029 基于价值观的领导者

表二

代码

KANT-015

KANT-016

KANT-017

KANT-028

KANT-029

如何将它们合并到一个数据集中以在一个网格视图中显示它们

这是我到目前为止所做的

conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;
                                Data Source =" + Server.MapPath("App_Data\\LR Product Database 2000.mdb"));
        conn.Open();

        setOleDb = new DataSet();
        OleDbDataAdapter dbaOle = new OleDbDataAdapter("SELECT * FROM tblProducts", conn);

        dbaOle.Fill(setOleDb);
        sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["LRVWebsite"].ToString());
        sqlCon.Open();
        dsSql = new DataSet();

        SqlDataAdapter dba = new SqlDataAdapter(@"SELECT C.CustomerFirstName,C.CustomerLastName, C.CustomerCompany,C.CustomerPosition,C.CustomerCountry,C.CustomerProvince,C.CustomerContact,CP.ActionDate,CP.ProductCode,CP.CustomerEmail FROM tblCustomers C INNER JOIN tblCustomerProducts CP ON C.CustomerEmail = CP.CustomerEmail ORDER BY ActionDate DESC", connString);
        //@"SELECT C.CustomerFirstName,C.CustomerLastName,C.CustomerCompany,C.CustomerPosition,C.CustomerCountry,C.CustomerProvince,C.CustomerContact,CP.ActionDate,CP.ProductCode,CP.CustomerEmail FROM tblCustomers C INNER JOIN tblCustomerProducts CP ON C.CustomerEmail = CP.CustomerEmail ORDER BY ActionDate DESC", connString);
        dba.Fill(dsSql);

        dsSql.Merge(setOleDb);

        GridView1.DataSource = dsSql;
        GridView1.DataBind();


        sqlCon.Close();
4

1 回答 1

1

您缺少 PK,合并发生在 PK 上。

在两张桌子上设置一个:

setOleDb.Tables[0].PrimaryKey = setOleDb.Tables[0].Columns["CODE"];
于 2013-01-15T08:26:09.907 回答