我对选择查询有疑问。我的目标是在 excel 表中选择一些列并将它们复制到我的 sql 表中。我有六列要复制。当我尝试复制由于标识列而更改的订单时。
这是我的代码;
string path = Server.MapPath(Session["excel_sheet"].ToString());
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd2 = new OleDbCommand("Select [column_1],[column_2],[column_3],[column_4],[column_5],[column_6] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd2.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(con);
//Give your Destination table name
sqlBulk.DestinationTableName = "MYtable";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
我的表有这样的列 identity_column,column_1,column_2,column_3,column_4,column_5,column_6。
例如在 excel column_4 字符串中的副本写入 sql column_3 后,它必须写入 column_4 。我正在等待答案