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 & "'"
            Try
                Conn.Open()
                Comm.ExecuteNonQuery()
                MsgBox("Time Submitted Sucessfully.")
                Conn.Close()
            Catch ex As Exception
                MsgBox("Unable to Submit.")
                Conn.Close()
            End Try

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

    End Sub

Open in new window

LVL 1
AnthonySmithMCPAsked:
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.")

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

so you can see what the actual error is
0

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?
0
planoczCommented:
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.
http://exceldatareader.codeplex.com/
0
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

0
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.