我有一个 18 列的 excel 表。其中 5 列具有相同的列名CALL_REASON
。但是当我使用 Microsoft.ACE.OLEDB.12.0 将该 Excel 表加载到数据集中时。对于具有相同名称的列,数据集中的列名称会更改。它被加载为CALL_REASON,CALL_REASON1,CALL_REASON2,CALL_REASON3,CALL_REASON4
. 它们在 excelsheet 中显示为CALL_REASON,CALL_REASON,CALL_REASON,CALL_REASON,CALL_REASON
String properties = "Excel 8.0; HDR=YES; IMEX=1;";//properties set for connection to excel
string sSourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\uploads\" + fileName + ";Extended Properties=\"" + properties + "\"";
sSourceConnection = new OleDbConnection(sSourceConstr);//creating the OLEDB connection
try
{
//select statement to select data from the first excel sheet
string sql = string.Format("Select * FROM [{0}]", "Sheet1$");
//commands to fill the dataset with excel data
OleDbDataAdapter excelAdapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
sSourceConnection.Open();
excelAdapter.SelectCommand = command;
excelAdapter.Fill(surveyItemDetails, "ExcelDataTable");
}