A
ad
I use the codes below to import the first sheet of an Excel file into a
DataSet.
But if the name of the first sheet is not "Sheet1", the SelectCommand will
fail.
How can I know the sheet name of the first Sheet in an Excel file?
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data
Source=" + savePath +
"; Extended Properties=" +
(char)34 + "Excel 8.0;IMEX=1;" + (char)34;
string sSelect = "SELECT * FROM [Sheet1$]";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand(sSelect, objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objAdapter1.Fill(ds, "XLData");
objConn.Close();
DataSet.
But if the name of the first sheet is not "Sheet1", the SelectCommand will
fail.
How can I know the sheet name of the first Sheet in an Excel file?
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data
Source=" + savePath +
"; Extended Properties=" +
(char)34 + "Excel 8.0;IMEX=1;" + (char)34;
string sSelect = "SELECT * FROM [Sheet1$]";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand(sSelect, objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objAdapter1.Fill(ds, "XLData");
objConn.Close();