[help] updating database using textbox in vb.net

Started on the old forum in October 2012 · view the original in the archive · old links redirect here

No replies · 587 views · started 14 years ago · 1 min read

Jervy Senior · 250 posts #1

Hi, I need a little help here. I'm Using vs 2005 with ms access 2003 database and finding myself how to get rid of this error "Syntax Error on UPDATE Statement" can you take a look at my codes below and tell me what's wrong? Thank you.

Public Class Transactions
    Dim cnnOLEDB As New OleDbConnection
    Dim cmdOLEDB As New OleDbCommand
    Dim cmdInsert As New OleDbCommand
    Dim cmdUpdate As New OleDbCommand
    Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\LibraryDatabase.mdb"
    Private Sub Transactions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.CenterToScreen()
    cnnOLEDB.ConnectionString = strConnectionString
    cnnOLEDB.Open()
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    i = "SELECT Lib_Book1,Lib_Book2,Lib_Book3 FROM members WHERE ID=" & txtmem_id.Text & " ;"
    j = "SELECT ID FROM books WHERE ID=" & txtbook_id.Text & " ;"
    If txtmem_id.Text <> "" And txtbook_id.Text <> "" And txtborrow_from.Text <> "" And txtborrow_until.Text <> "" Then
    cmdUpdate.CommandText = "UPDATE books SET Borrowed_By, Bk_Status, Bk_From, Bk_Due = '" & txtmem_id.Text & "', '" & "Borrowed" & "', '" & txtborrow_from.Text & "', '" & txtborrow_until.Text & "' WHERE ID = " & txtbook_id.Text & ";"
    cmdUpdate.CommandType = CommandType.Text
    cmdUpdate.Connection = cnnOLEDB
    cmdUpdate.ExecuteNonQuery()
    MsgBox("Transaction Recorded.")
    txtmem_id.Text = String.Empty
    txtbook_id.Text = String.Empty
    txtborrow_from.Text = String.Empty
    txtborrow_until.Text = String.Empty
    Else
    MsgBox("Error to be set later!")
    End If
    cmdUpdate.Dispose()
    End Sub

Anyone knows how to solve this?

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close