The company asked me to import an Execl to SQL Server. However, fields are different from databases. Then the content of the corresponding field does not comply with the database standards. No way... you can only read it.
Public DataSet GetExcel ()
{
String strCon = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = c: \ sample.xls; Extended Properties = Excel 8.0"; // connect to Excel
OleDbConnection myConn = new OleDbConnection (strCon );
String strCom = "SELECT * FROM [Sheet2 $]"; // The table name of Sheet2 comes FROM the lower left corner of Excel. I didn't understand what this is.
MyConn. Open ();
// Open the data link to obtain a dataset
OleDbDataAdapter myCommand = new OleDbDataAdapter (strCom, myConn );
// Create a DataSet object
DataSet myDataSet = new DataSet ();
// Get your own DataSet object
MyCommand. Fill (myDataSet, "[Sheet2 $]");
// Close the data link
MyConn. Close ();
Return myDataSet;
}