我正在使用以下代碼將Excel文件更新到SQL Server中。代碼正在工作,但不能將第一行插入到表中。無法使用SqlBulkCopy從Excel中讀取第一行
OleDbConnection OleDb = new OleDbConnection(ConnectionString);
OleDbCommand OleDbCmm = new OleDbCommand(Query,OleDb);
OleDbDataReader OleDbdr;
OleDb.Open();
if (OleDb.State == ConnectionState.Open)
{
OleDbdr = OleDbCmm.ExecuteReader();
SqlBulkCopy BulkCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["connstring"].ToString());
BulkCopy.DestinationTableName = "TempTable";
if (OleDbdr.Read())
{
BulkCopy.WriteToServer(OleDbdr);
}
}
OleDb.Close();
感謝您的回覆,但我使用以下連接字符串「Provider = Microsoft.Jet.OLEDB.4.0; Data Source ='」+ FilePath +「'; Jet OLEDB:Engine Type = 5; Extended Properties = \」Excel 8.0; HDR =否; IMEX = 1 \「」 – ravi
@ravi,請看最新的編輯。 – RePierre