I notice that you do not have a where clause, so this command will effectively Update EVERY record in your table. Is that the intention?
AW
Main Topics
Browse All Topics Dim connectionString As String = _
"Provider=Microsoft.Jet.OL
"Data Source=" & Application.StartupPath & "\Inventory.mdb;" & _
"User ID=Admin;" & _
"Password="
Dim logInOleDbConnection As New OleDbConnection(connection
' Create a ADO.NET OleDbCommand.
Dim sqlInventoryString As String = "UPDATE Inventory ([First Name],[Last Name], [Phone], [Description],[Order Placed],[Order Shipped],[Order Received],[Comments],[Ship
Dim sqlCommand As New OleDb.OleDbCommand(sqlInve
' Open the database connection.
logInOleDbConnection.Open(
' Run the sqlCommand.
Dim countFound As Integer = CType(sqlCommand.ExecuteSc
' Close the database connection.
logInOleDbConnection.Close
' If countFound = 1 a record with a matching UserName and Password
' was found..
If countFound = 1 Then
Label13.Text = "Insert Unsuccessful please try again"
Else
Label13.Text = "Update Successful"
txtfirstname.Clear()
txtlastname.Clear()
txtdescription.Clear()
richtxtcomments.Clear()
txtphone.Clear()
txtshipping.Clear()
richtxtcomments.Clear()
checkboxorderplaced.Checke
checkboxordershipped.Check
checkboxorderreceived.Chec
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
RadioButton5.Checked = False
End If
Is my code. I am trying to do a update statement from a VB form into a access Db using a button click. Any help?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
"You are correct it should update what ever is in that specific text box" what does that mean?
You need to specify which RECORD in the table to update, using a WHERE clause in the SQL. Yes, you will use the Textboxes for the source of the values to update the fileds TO, but they will not specify WHICH single record is to be updated.
and where does your syntax error come in? you have only shown me the SQL that you are trying to use to update the table. You use an
sqlCommand.ExecuteNONScala
to execute an Update query.
AW
First thing is that this is a Access Query String. There is not a ExecuteNonScalar(). I added what you suggested being a where [id] = '"& txtid.text & "'. I am still getting Syntax Errors. I hope you or someone can fix it!
Dim connectionString As String = _
"Provider=Microsoft.Jet.OL
"Data Source=" & Application.StartupPath & "\Inventory.mdb;" & _
"User ID=Admin;" & _
"Password="
Dim updatequery As New OleDbConnection(connection
' Create a ADO.NET OleDbCommand.
******* Access Query String ******
Dim sqlInventoryString As String = "UPDATE Inventory Set [First Name] = '" & txtfirstname.Text & "' , [Last Name] = '" & txtlastname.Text & "', [Phone] = '" & txtphone.Text & "', [Description] = '" & txtdescription.Text & "', [Order Placed] = '" & checkboxorderplaced.Checke
Dim sqlCommand As New OleDb.OleDbCommand(sqlInve
' Open the database connection.
updatequery.Open()
' Run the sqlCommand.
Dim countFound As Integer = CType(sqlCommand.ExecuteNo
' Close the database connection.
updatequery.Close()
' If countFound = 1 a record with a matching UserName and Password
' was found..
If countFound = 1 Then
tmlabel.Text = "Update Unsuccessful please try again"
Else
tmlabel.Text = "Update Successful"
Me.tmfirstname.Clear()
Me.tmlastname.Clear()
Me.tmdescripition.Clear()
Me.tmphone.Clear()
Me.tmshipping.Clear()
Me.tmorderplaced.Checked = False
Me.tmorderreceived.Checked
Me.tmordershipped.Checked = False
Me.tmovernight.Checked = False
Me.tmground.Checked = False
Me.tm2day.Checked = False
Me.tm3day.Checked = False
Me.tmother.Checked = False
buttonload.Visible = True
tmlistbox.Visible = False
buttonupdate.Visible = False
buttonedit.Visible = False
ok, what was confusing me was that you are using a variable named sqlCommand to hold an OleDb.OleDbCommand object, so the names were confusing, as I read this to be an SqlCommand object.
With your existing code:
1) an SQL Update command will NOT return any value, so your line:
Dim countFound As Integer = CType(sqlCommand.ExecuteNo
cannot possibly succeed, since there is no value returned, to convert to an Integer
2) try this change:
replace:
Dim countFound As Integer = CType(sqlCommand.ExecuteNo
with
sqlCommand.ExecuteNonScala
the fact that this is a ADO.NET OleDb.OleDbCommand object means that regardless of the specific backend Database (Access, or otherwise), there is an ExecuteNonScalar method on the OleDbCommand object, that is used to execute SQL commands that do NOT return values (Such as DELETE, UPDATE, ALTER TABLE)
AW
Sorry, I was sort of right the first time.
replace:
Dim countFound As Integer = CType(sqlCommand.ExecuteNo
with
Dim countFound As Integer = sqlCommand.ExecuteNonQuery
The return value should be the number of rows updated by the SQL, and returns an Integer value by definition, so no need to use cType to convert the resulting value to an Integer - it already is one.
AW
I am still getting UPDATE syntax erros?? whats wrong with me update statment? I am sooo sorry this is taking so long I am kinda new to coding
Dim sqlInventoryString As String = "UPDATE Inventory Set ([First Name] = '" & txtfirstname.Text & "' , [Last Name] = '" & txtlastname.Text & "', [Phone] = '" & txtphone.Text & "', [Description] = '" & txtdescription.Text & "', [Order Placed] = '" & checkboxorderplaced.Checke
Is your ID field a NUMBER or TEXT?
If it is a Number, then drop the '...' around txtID.Text.
also, drop the (...) around the Set part:
Dim sqlInventoryString As String = "UPDATE Inventory Set [First Name] = '" & txtfirstname.Text & "' , [Last Name] = '" & txtlastname.Text & "', [Phone] = '" & txtphone.Text & "', [Description] = '" & txtdescription.Text & "', [Order Placed] = '" & checkboxorderplaced.Checke
The proper syntax is
Update <TableName> SET Field1 = Value1, Field2 = Value2, Field3 = Value3 Where Field4 = Value4
NOT
Update <TableName> SET (Field1 = Value1, Field2 = Value2, Field3 = Value3) Where Field4 = Value4
THIS STATEMENT IS IN ERROR
AW
This thing is being a pain in the butt.
txt ID is a text box that has the ID number from the table in it. So you make that call ha ha
new error:
Data type mismatch in criteria expression. at the Dim countFound As Integer = sqlCommand.ExecuteNonQuery
You really dont know how much help you have been! Thanks
Business Accounts
Answer for Membership
by: Arthur_WoodPosted on 2007-04-15 at 15:55:22ID: 18914978
the proper syntax to use the Update statement is:
d & ", [Order Shipped] = " & checkboxordershipped.Check ed & ", [Order Received] = " & checkboxorderreceived.Chec ked & ", [Comments] = '" & richtxtcomments.Text & "', [Shipping] = '"& txtshipping.Text & "', [Updated By])='" & LogOnForm.UserNameTextBox. Text & "');"
UPDATE [tableName] Set Field1=Value1, Field2=Value2 where filed3 = Value3
so your statement should read:
Dim sqlInventoryString As String = "UPDATE Inventory Set [First Name] = '" & txtfirstname.Text & "' , [Last Name] = '" & txtlastname.Text & "', [Phone] = '"& txtphone.Text & "', [Description] = '" & txtdescription.Text & "', " & [Order Placed] = " checkboxorderplaced.Checke
I think I got all of the " and ' in the right place.
AW