English 中文(简体)
采用捆绑制成的带多种数据的外壳
原标题:Error of writing excel with a number of data by Using oledb
  • 时间:2012-01-12 04:39:35
  •  标签:
  • c#

我在将数据插入使用捆绑器的Excel方面遇到问题。

问题:当我试图将不到65,000条线的数据写进Excel时,它就发挥了作用。 但当我试图写上65,000多条线时,出现了错误:

读书全文

我猜测,在某一时间写字日有限制......

我有超过1 000 000条数据线来书写......

a 包括6栏和约100字。

这里是我的源代码。

private static OleDbConnection CreateConnection(string ExcelPath)
    {
        OleDbConnectionStringBuilder ConnectionBuilder = new OleDbConnectionStringBuilder();
        ConnectionBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
        ConnectionBuilder.DataSource = ExcelPath;
        ConnectionBuilder.Add("Extended Properties", "Excel 8.0");
        return new OleDbConnection(ConnectionBuilder.ToString());
    }

using (OleDbConnection Connection = CreateConnection(@"C:userinfo.xls"))
        {
            Connection.Open();
            OleDbCommand tempCmd = Connection.CreateCommand();
            tempCmd.CommandText = CreateTableQury(dt, "Sheet1");
            tempCmd.ExecuteNonQuery();
            tempCmd.CommandText = CreateInsertQuery(dt, tempCmd.Parameters, "Sheet1");
            int extime = 1;
            foreach (DataRow Row in dt.Rows)
            {
                for (int t = 0; t < tempCmd.Parameters.Count; t++)
                {
                    tempCmd.Parameters[t].Value = Row[t];

                }
                tempCmd.ExecuteScalar();
                extime++;
                if ((extime % 1000) == 0)
                {
                    Console.WriteLine("EXCEL " + extime + " Line / time:" + sw.Elapsed.ToString());
                }
            }
            Connection.Close();
        }


public static string CreateTableQury(DataTable Table, string SheetName)
    {
        string Query = "CREATE TABLE [" + SheetName + "] (";

        for (int i = 0; i < Table.Columns.Count; i++)
        {
            Query += Table.Columns[i].ColumnName + " text";
            if (i < Table.Columns.Count - 1) Query += ", ";
            else Query += ")";
        }

        return Query;
    }

    public static string CreateInsertQuery(DataTable Table, OleDbParameterCollection Parameters, string SheetName)
    {

        string Query = @"INSERT INTO [" + SheetName + "] VALUES (";

        for (int i = 0; i < Table.Columns.Count; i++)
        {
            Query += "@Param" + i.ToString();

            if (i < Table.Columns.Count - 1) Query += ", ";
            else Query += ")";

            OleDbParameter Parameter = new OleDbParameter("@Param" + i.ToString(), DbType.String);
            Parameters.Add(Parameter);

        }

        return Query;
    }
问题回答

该版本可能在2003年启用。 由于你在2007年开斋节时,它赢得了65公里以上的输电。

因此, 请在2007年节省费用,并尝试这样做。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签