0
private void button1_Click(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings["db"].ConnectionString;

            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand("SELECT * FROM Sheet1$", con);

            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataTable dt = new DataTable();
            sda.Fill(dt);
            //BindingSource bsource = new BindingSource();
            //bsource.DataSource = dt;
            //dataGridView1.DataSource = bsource;
            //sda.Update(dt);

            DataSet ds = new DataSet();
            ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
            sda.Fill(dt);
            ds.Tables.Add(dt);
            ExcelLibrary.DataSetHelper.CreateWorkbook("D:\\ChallanBulkUpload\\ChallanBulkUpload\\ChallanBulkUpload\\UploadFile\\challan.xls", ds);

        }
7
  • 5
    "For this reason my code doesn't work" what error do you get? have you tried selecting and inserting your data in batches? Commented Dec 2, 2015 at 10:45
  • when i click button , it show me This webpage is not available Commented Dec 2, 2015 at 11:06
  • Can you post the code invoked on the click of your button? Commented Dec 2, 2015 at 11:18
  • @Md.MehediHassan ok. really, what kind of debugging have you been doing? did you set breakpoints and step through your code? do you catch exceptions and log them to a logfile? Commented Dec 2, 2015 at 11:19
  • Now i tried different way. I'm updated the code that i posted. Please see it. But give me error like Invalid cell value when i want to upload more than 50k data. But 35k data upload successfully.I want to upload more than 100k data. what's the problem ? please help me. I can't understand the problem. Commented Dec 2, 2015 at 17:55

1 Answer 1

1

In my experience, using oledb to process excel files is a bit buggy. I switched over to using OpenXml (http://www.microsoft.com/en-us/download/details.aspx?id=30425). Maybe also a solution for you ....

Update: You can also use excel interop to process excel files (xls), see https://msdn.microsoft.com/en-us/library/ms173186(v=vs.80).aspx

For this to work, Excel has to be installed on the system.

Sign up to request clarification or add additional context in comments.

3 Comments

FYI: OpenXml can not create xls files, it can only create the newer xlsx format that Microsoft switched to starting with Office 2003.
so, tell me what can i do ? I want to export more than 100k data from sql server to excel sheet with header. This will be C# windows forms application under button click.
You are not saying why @Poiter answer is not sufficient for you. You have not stated you need XLS format, and have not provided any feedback as to why the suggested answer is incorrect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.