Insert row in excel with c# RRS feed

  • Question

  • Hello, I'm trying to write into an Excel file used as template.


    String m_sConn1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileDestinazione + ";Extended Properties=\"Excel 8.0;HDR=NO\"";

    OleDbConnection conn = new OleDbConnection(m_sConn1);


    for (int j = 0; j < rowCount2 - 1; j++)


    OleDbCommand comm = new OleDbCommand();

    comm.Connection = conn;

    string values = "";



    //value get is value


    values = values.Replace("''", "' '");

    if (values.Contains("NULL"))

    values = values.Replace("'NULL'", "' '");

    comm.CommandText = "insert into [" + "Dla klienta$" + "] values(''," + values + ")";





    catch (Exception ex)










    For some reason this code works well on my machine but not on others.

    Can you help me to find the reason?


    Thursday, February 7, 2008 5:56 PM

All replies

  • Your question is not about VSTO, but ADO.NET. I'm therefore moving your message to the ADO.NET forum.


    The VSTO technology is a set of tools that extends the UI in some Office 2003 and 2007 applications. While it does use data binding, trouble-shooting connections and SQL is not supported here.


    Thursday, February 7, 2008 8:19 PM
  • ok.


    Friday, February 8, 2008 8:53 AM
  • What is definition of not working on another PC? Do you get any exception? Make sure that Jet OLEDB provider is installed on other PC, since Jet OLEDB is not part of MDAC for several years and is not installed automatically with Windows. You could download latest version of it (SP8) from the link below and pay attention that it is platform-dependant

    Friday, February 8, 2008 10:48 AM
  • Thank's for response.


    The exception found is "Tipo di dati non corrispondenti nell'espressione criterio"  (Data type mismatch in criteria expression).


    I try also to write into a blank template and, in this case, insert works well on all machines, so I think Jet is installed everywhere.


    How can I verify Jet OLEDB version installed?


    Why same version of template generate different response of my application on different pcs?







    Friday, February 8, 2008 11:00 AM