18列のExcelシートがあります。その5つの列には同じ列名がありCALL_REASON
ます。しかし、Microsoft.ACE.OLEDB.12.0 を使用してその Excel シートをデータセットに読み込むと、. 同じ名前の列について、データセットの列名が変更されます。としてロードされていCALL_REASON,CALL_REASON1,CALL_REASON2,CALL_REASON3,CALL_REASON4
ます。それらはExcelシートに次のように存在します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");
}