使用OleDbConnection,OleDbCommand

时间:2018-07-08 16:52:30

标签: c# asp.net .net oledbcommand oledbdataadapter

下面的代码片段可以很好地读取5000-6000行,但不能超过10000行。当我使用SELECT * FROM Sheet1 $ A1:DC20000时,dtdata只有8327行。

string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + templatepath + ";Extended Properties=Excel 12.0;";
                        string Extension = Path.GetExtension(templatepath);
       if (Extension == ".xls")
           connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + templatepath + ";Extended Properties=Excel 8.0";

    OleDbConnection conn = new OleDbConnection(connstr); 

    strSQL = "SELECT * FROM Sheet1$A1:DC20000";
        OleDbCommand cmd = new OleDbCommand(strSQL, conn);
                            cmd.CommandTimeout = 5000;
                            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                            da.Fill(dtdata);
                            dtdata.TableName = "Table0";
                            dsdata.Tables.Add(dtdata);

0 个答案:

没有答案