• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Updating Excel Spreadsheet in VB.net

Hello, I’m putting together a .net application that uses excel as its database. I’m trying to get my application update records in the excel database. I’m able to read data from the database using my application so it’s setup correctly. Can someone please assist me with this? I think the trouble I’m having is that I need to use the values from my textboxes (This is the data that will be used to update the database). But I’m not sure how to code the Comm.Command.text = Update…. Command. Please see my code below.

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles SubmitTime.Click

        Dim WEdate As String
        Dim HRworked As String
        Dim Empname2 As String
        Empname2 = EmpName.Text
        HRworked = TotalHrs.Text
        WEdate = ComboBox1.Text

        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand
        Conn.ConnectionString = CreateConnString("c:\Data\TimeData.xls")
        Comm.Connection = Conn
        Comm.CommandText = "Update" & WEdate & "SET HoursWorked =" & HRworked & "Where Ename = " & EmpName & ""
        Catch ex As Exception
        End Try
    End Sub

Open in new window

1 Solution
AnthonySmithMCPAuthor Commented:
I got it working with the following statement:

Comm.CommandText = "update [TimeData$] set WeekEnding='" & TotalHrs.Text & "' where Ename = '" & EmpName.Text & "'"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now