Ryan Smith
asked on
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 & ""
Try
Conn.Open()
Comm.ExecuteNonQuery()
MsgBox("Updated.")
Conn.Close()
Catch ex As Exception
MsgBox("Error.")
Conn.Close()
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.