1 Replies - 262 Views - Last Post: 27 November 2012 - 10:44 AM Rate Topic: -----

#1 m0h1t  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-November 10

Error while writing a List<int> into an xlsx file

Posted 27 November 2012 - 09:45 AM

OK, I have some code and I need to write a list<> of integers onto an xlsx file. But am getting an error.
Here is the code.

            string fileName = @"C:\rhandx.xlsx";
             string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                      fileName + ";Extended Properties=\"Excel 8.0;HDR=NO;\"";
            OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
            con.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = con;
            foreach (int coord in rhandlist)
            {
                cmd.CommandText = ("INSERT INTO TABLE [SHEET1$] VALUES (coord)");
                cmd.ExecuteNonQuery();
            }
            con.Close();



rhandlist is a list with unknown no of int's. But I get an error saying my insert statement's syntax is wrong.

Is This A Good Question/Topic? 0
  • +

Replies To: Error while writing a List<int> into an xlsx file

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Error while writing a List<int> into an xlsx file

Posted 27 November 2012 - 10:44 AM

You include the range separator but don't include a range. Try removing the $ or add a range.

This post has been edited by Momerath: 27 November 2012 - 10:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1