Exporting data to Excel cells

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasasasa
    New Member
    • Apr 2010
    • 29

    Exporting data to Excel cells

    How can I update an existing excel file? I want to change certain values already present in the excel file and I am using


    Code:
     
    Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Test.xlsx;Extended Properties=""Excel 12.0 Xml;HRD=No""" 
            Dim excelConnection As New OleDbConnection(excelConnectionString) 
            excelConnection.Open() 
    Dim strsql As String =  = "UPDATE [Sheet1$A3:A3] SET F1 = 'Test'" 
     Dim cmd1 As New OleDbCommand(strsql, excelConnection) 
                cmd1.ExecuteNonQuery() 
                excelConnection.Close()
    It gives me the error saying that there is a requirement of one or more parameters. What should I do? Please help.
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    What line gives you the error? Have you tried searching the MSDN for the method you are using? Most of the times, all parameters (both mandatory and optional) are listed there.

    Steven

    Comment

    • sasasasa
      New Member
      • Apr 2010
      • 29

      #3
      This is the actual error
      "No value given for one or more required parameters."

      This line is giving error
      cmd1.ExecuteNon Query()

      Code:
      Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Test.xlsx;Extended Properties=""Excel 12.0 Xml;HRD=No"""  
              Dim excelConnection As New OleDbConnection(excelConnectionString)  
              excelConnection.Open()  
      Dim strsql As String = "UPDATE [Sheet1$A3:A3] SET F1 = 'Test'"  
       Dim cmd1 As New OleDbCommand(strsql, excelConnection)  
                  cmd1.ExecuteNonQuery()  '<<<-----Error
                  excelConnection.Close()

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        Perhaps this link might help you: http://msdn.microsoft.com/en-us/libr...arameters.aspx

        Steven

        Comment

        Working...