| | |
Syntax error in UPDATE statement.
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 11
Reputation:
Solved Threads: 0
I'm trying to determine why I receive this error message when attempting to update the database.."Syntax error in UPDATE statement", please assist!
Thanks!
Thanks!
vbnet Syntax (Toggle Plain Text)
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Dim SQLStmt As String Dim UpdateOK As Integer If txtFirstName.Text = "" And txtLastName.Text = "" Then MsgBox("All Account records must have at least a last or first name. Companies' names should be entered in the LastName field, leaving the FirstName field empty...") txtLastName.Focus() Return End If Dim UpdateCnxn As New OleDbConnection( _ "Provider=Microsoft.ACE.OLEDB.12.0;" _ & "Data Source=DB.mdb") UpdateCnxn.Open() 'escape any quotes to avoid problems with SQL... txtLoginId.Text.Replace("'", "''") txtPassword.Text.Replace("'", "''") txtFirstName.Text.Replace("'", "''") txtLastName.Text.Replace("'", "''") If lblId.Text = "New" Then SQLStmt = String.Format("insert into ACCOUNTS (LoginId, LoginPwd, Primary Role, FirstName, LastName) values ('{0}', '{1}', '{2}', '{3}', '{4}')", _ txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtLastName.Text, txtFirstName.Text) Else SQLStmt = String.Format("update ACCOUNTS set LoginId='{0}', LoginPwd='{1}', Primary Role='{2}', FirstName='{3}', LastName='{4}' where Id={5}", _ txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtFirstName.Text, txtLastName.Text, lblId.Text) End If Dim UpdateCommand As New OleDbCommand(SQLStmt, UpdateCnxn) Debug.Write("UpdateSQLStmt=" & SQLStmt & vbCrLf) UpdateOK = UpdateCommand.ExecuteNonQuery() UpdateCnxn.Close() ClearInputAreas() txtSearch.Text = "" lblAdvice.Text = "Enter some characters of the last name, or company name, to search for an Account. Or, enter the Account # if you have it. Click the New button to create a new account record." txtSearch.Focus() End Sub
Last edited by cscgal; Sep 27th, 2008 at 8:07 pm. Reason: Added code tags
•
•
Join Date: Sep 2008
Posts: 11
Reputation:
Solved Threads: 0
Correction to my last reply!!!!!
I'm now receiving this error message, please assist:
"Data type mismatch in criteria expression."
CODE
I'm now receiving this error message, please assist:
"Data type mismatch in criteria expression."
CODE
vbnet Syntax (Toggle Plain Text)
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Dim SQLStmt As String Dim UpdateOK As Integer If txtFirstName.Text = "" And txtLastName.Text = "" Then MsgBox("All Account records must have at least a last or first name. Companies' names should be entered in the LastName field, leaving the FirstName field empty...") txtLastName.Focus() Return End If Dim UpdateCnxn As New OleDbConnection( _ "Provider=Microsoft.ACE.OLEDB.12.0;" _ & "Data Source=DB.mdb") UpdateCnxn.Open() 'escape any quotes to avoid problems with SQL... txtLoginId.Text.Replace("'", "''") txtPassword.Text.Replace("'", "''") txtFirstName.Text.Replace("'", "''") txtLastName.Text.Replace("'", "''") If lblId.Text = "New" Then SQLStmt = String.Format("insert into ACCOUNTS (LoginId, LoginPwd, PrimaryRole, FirstName, LastName,) Id values '{0}', '{1}', '{2}', '{3}', '{4}'),", _ txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtFirstName.Text, txtLastName.Text) Else SQLStmt = String.Format("update ACCOUNTS set LoginId='{0}', LoginPwd='{1}', PrimaryRole='{2}', FirstName='{3}', LastName='{4}' where Id= '{5}'", _ txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtFirstName.Text, txtLastName.Text, lblId.Text) End If Dim UpdateCommand As New OleDbCommand(SQLStmt, UpdateCnxn) Debug.Write("UpdateSQLStmt=" & SQLStmt & vbCrLf) UpdateOK = UpdateCommand.ExecuteNonQuery() UpdateCnxn.Close() ClearInputAreas() txtSearch.Text = "" lblAdvice.Text = "Enter some characters of the last name, or company name, to search for an Account. Or, enter the Account # if you have it. Click the New button to create a new account record." txtSearch.Focus() End Sub
Last edited by cscgal; Sep 28th, 2008 at 1:31 am. Reason: Added code tags
Hi,
I guess the error may be at line 19
I think this not in the format of
INSERT INTO TABLE (Field1, Field2, ...)
VALUES (Val1, Val2, ..)
May be its your typing mistake.
Corrected may be
Before execute the Query check the Query SQL.
Another possible Error May be:
You are considering all the fields are String and give them for single quote. It may be differ in the original table.
For example you have given id as Text. but it may be numeric type. So Check the Type of the Field in the Access Table
I guess the error may be at line 19
VB Syntax (Toggle Plain Text)
SQLStmt = String.Format("insert into ACCOUNTS (LoginId, LoginPwd, PrimaryRole, FirstName, LastName,) Id values '{0}', '{1}', '{2}', '{3}', '{4}'),", _ txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtFirstName.Text, txtLastName.Text)
I think this not in the format of
INSERT INTO TABLE (Field1, Field2, ...)
VALUES (Val1, Val2, ..)
May be its your typing mistake.
Corrected may be
VB Syntax (Toggle Plain Text)
SQLStmt = String.Format( "insert into ACCOUNTS (LoginId, LoginPwd, PrimaryRole, FirstName, LastName) values ('{0}', '{1}', '{2}', '{3}', '{4}')", _ txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtFirstName.Text, txtLastName.Text)
Another possible Error May be:
You are considering all the fields are String and give them for single quote. It may be differ in the original table.
For example you have given id as Text. but it may be numeric type. So Check the Type of the Field in the Access Table
Last edited by selvaganapathy; Sep 28th, 2008 at 11:57 am.
KSG
![]() |
Similar Threads
- syntax Error.. (VB.NET)
- Syntax error in INSERT INTO statement (Java)
- Problems on Insert and Update Statement (C#)
- Problems on Insert and Update (C#)
- Insert and Update Errors (C#)
- Help with Dataset update (VB.NET)
- UPDATE syntax error (MySQL)
- ADO.Net SQL UPDATE using OleDBAdapter (C#)
Other Threads in the VB.NET Forum
- Previous Thread: how to clear specific column in datagridview
- Next Thread: Help Needed to build a dynamic SQL query string in VB.NET
| Thread Tools | Search this Thread |
"crystal .net .net2008 2008 access add advanced application array assignment basic beginner box browser button buttons center click code combo convert cpu cuesent data database datagrid datagridview datetimepicker designer dissertation dissertations dissertationtopic dosconsolevb.net editvb.net employees excel exists firewall forms html images isnumericfuntioncall listview map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity open pan pdf picturebox picturebox2 port position print printpreview record regex reuse right-to-left save search serial settings socket sorting sqldatbase sqlserver storedprocedure temp textbox timer timespan transparency txttoxmlconverter useraccounts usercontol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf wrapingcode xml year





