please help! Error in update Access database

  • Thread starter Thread starter Rabi
  • Start date Start date
R

Rabi

I have been trying to update in Access Database. I get this error "Syntax
error in UPDATE statement." What could be the problem or can somebody
suggest different solution.

I call this function from my main page.

Public Shared Function UpdateScholarship(ByVal ID As String, ByVal Name As
String, ByVal Amount As String, ByVal Year As String, ByVal Criteria As
String, ByVal Conditions As String)

Dim connection As New OleDbConnection(ConnectionToDatabase)

Dim UpdateString As String = "Update ScholarshipDescription Set
[Name]='" & Name & "', Amount='" & Amount & "', Year='" & Year & "',
Criteria='" & Criteria & "', conditions='" & Conditions & "' Where ID='" &
ID & "'"

Dim command As New OleDbCommand(UpdateString, connection)

connection.Open()
command.ExecuteNonQuery()
connection.Close()
 
Do yourself a favor and build a Parameter-driven query. This will address a
litany of issues when executing action commands (as you have found).

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
 
Are all of those fields defined as text fields in the database?
Because you are certainly updating them as if they were.

Robin S.
 
Rabi,

Have at least beside the answers you got a look that you don't take
keywords.

I don't know if Access will by instance accept year,

Cor
 
¤ I have been trying to update in Access Database. I get this error "Syntax
¤ error in UPDATE statement." What could be the problem or can somebody
¤ suggest different solution.
¤
¤ I call this function from my main page.
¤
¤ Public Shared Function UpdateScholarship(ByVal ID As String, ByVal Name As
¤ String, ByVal Amount As String, ByVal Year As String, ByVal Criteria As
¤ String, ByVal Conditions As String)
¤
¤ Dim connection As New OleDbConnection(ConnectionToDatabase)
¤
¤ Dim UpdateString As String = "Update ScholarshipDescription Set
¤ [Name]='" & Name & "', Amount='" & Amount & "', Year='" & Year & "',
¤ Criteria='" & Criteria & "', conditions='" & Conditions & "' Where ID='" &
¤ ID & "'"
¤
¤ Dim command As New OleDbCommand(UpdateString, connection)
¤
¤ connection.Open()
¤ command.ExecuteNonQuery()
¤ connection.Close()
¤

Year is a reserved keyword (function). I would recommend against using it for a column name. If you
do use a reserved keyword then it must be enclosed within brackets.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top