VB.net comman.text - Database not updating

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? When I run my application I’m getting “Unable to Submit” (My error).  It might be my syntax and 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

        If Not TotalHrs.Text = "" Then

            Dim Conn As New OleDbConnection
            Dim Comm As New OleDbCommand
            Conn.ConnectionString = CreateConnString("c:\Data\TimeData.xls")
            Comm.Connection = Conn
            Comm.CommandText = "update [TimeData$] set '" & ComboBox1.Text & "'='" & TotalHrs.Text & "' where Ename = '" & EmpName.Text & "'"
                MsgBox("Time Submitted Sucessfully.")
            Catch ex As Exception
                MsgBox("Unable to Submit.")
            End Try

            MsgBox("Please calculate your time before submitting")
        End If

    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
If you run the program in debug can you see what the value of ex is when it hits the line where you display 'Unable To Submit'

or maybe change the line :

MsgBox("Unable to Submit.")

MsgBox("Unable to Submit - " & ex.Message)

so you can see what the actual error is

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul MacDonaldDirector, Information SystemsCommented:
Additionally, how certain are you "ComboBox1.Text" will always be a valid field name?
there is a open source  code you my be able to use a little easier. It reads to a excel
sheet by using a dataset.
AnthonySmithMCPAuthor Commented:
Thanks everyone for the help but the problem was I need a space after the = sign..

In my code:
 Comm.CommandText = "update [TimeData$] set '" & ComboBox1.Text & "'='" & TotalHrs.Text & "' where Ename = '" & EmpName.Text & "'"

Open in new window

But it needed to be:

            Comm.CommandText = "Update [TimeData$] SET " & ComboBox1.Text & "= '" & TotalHrs.Text & "' where Ename = '" & EmpName.Text & "'"

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.