Home > Net >  OleDbConnection reading Excel data
OleDbConnection reading Excel data

Time:11-08

The DataSet ds=new DataSet ();
//Excel data source compatible (03/10)
String path="Provider=Microsoft. ACE. The OLEDB. 12.0; Persist Security Info=true; Data Source="+ ExcelPath +"; Extended Properties=\ "Excel 12.0; HDR=No. IMEX=2; \ "";
Int Count=0;
String ISOK="";
//connection
Using (OleDbConnection conn=new OleDbConnection (path))
{
conn.Open();
//get all of the Excel sheet
DataTable dtSheet=conn. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, new object [] {null, null, null, "TABLE"});
String [] StrSheetName=new string [dtSheet. Rows. Count];
//meets the requirements in the Excel sheet data read
in a TableFor (int I=0; i {
//it meets the requirements of table number
String tableName=dtSheet. Rows [I] [r]. "TABLE_NAME" ToString ();
If (tableName. Contains (" credentials subsidiary $'))
{
OleDbDataAdapter OleDa=new OleDbDataAdapter (" select * from [" + tableName + "] ", conn);
OleDa. The Fill (ds, tableName);
}
}
//the Table data into database
ISOK=UpDetailedSummaryLoad (ds, Year);//this is read to the database data
ISOK=ISOK + ", "+ ds. Tables [0]. Rows. Count;//the data read from the Excel test environment have 3 w data, formal only 7000 data
};
Return ISOK.//the Convert. ToInt32 (ISOK);
}

I when reading Excel, in a test environment Excel within 3 w can read data, but can only read the article 7000 in formal environment data, is this why
  •  Tags:  
  • C#
  • Related