我正在尝试在 asp.net 中合并两个 excel 文件,并将它们作为一个表格显示在 gridview 中。下面的代码只显示一个表。谁能告诉我下面的代码有什么问题?如果您有更好的想法,请告诉我。
protected void MergTables()
{
string connString = ConfigurationManager.ConnectionStrings[hwTypes].ConnectionString;
OleDbConnection DBConnection = new OleDbConnection(connString);
DBConnection.Open();
OleDbCommand DBCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", DBConnection);
OleDbDataAdapter da = new OleDbDataAdapter(DBCommand);
DataSet ds = new DataSet("Stock");
da.Fill(ds, "HWTypes");
DBConnection.Close();
string _stockConn = ConfigurationManager.ConnectionStrings[stockConn].ConnectionString;
DBConnection = new OleDbConnection(_stockConn);
DBConnection.Open();
DBCommand = new OleDbCommand("SELECT * FROM [Stock_voorlopig$]", DBConnection);
da = new OleDbDataAdapter(DBCommand);
da.Fill(ds, "Stock");
DBConnection.Close();
for (int i = 0; i < ds.Tables["HWTypes"].Rows.Count; i++)
{
ds.Tables["HWTypes"].Rows[i]["ProductID"] = ds.Tables["Stock"].Rows[i]["Partno"];
}
GridView1.DataSource = ds.Tables["Stock"];
GridView1.DataBind();
}