|
-
Jan 27th, 2010, 11:39 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] SQL help! What am i doing wrong?
Hi all,
The following code
Code:
Function AddToDatabase(ByVal TAG As String, ByVal EquipmentType As String, ByVal Description As String, ByVal Status1 As String, ByVal Status2 As String, ByVal DateChanged As Date, ByVal Comments As String, ByVal UserID As String) As Boolean
'Write to the Database
Try
Dim connectionSQL As New OleDbConnection(strSQLconn & DataSourcePath)
Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID", connectionSQL)
connectionSQL.Open()
MsgBox(connectionSQL.State.ToString)
With command.Parameters
.AddWithValue("@EquipmentType", EquipmentType)
.AddWithValue("@TAG", TAG)
.AddWithValue("@Descriptor", Description)
.AddWithValue("@Status1", Status1)
.AddWithValue("@Status2", Status2)
.AddWithValue("@DateChanged", "01/01/2010")
.AddWithValue("@Comments", Comments)
.AddWithValue("@Userid", UserID)
End With
command.ExecuteNonQuery()
'command.Dispose()
'Need to reset the form for the next one
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetText(ex.ToString)
Return False
End Try
End Function
Generates this error
Code:
System.Data.OleDb.OleDbException was caught
ErrorCode=-2147217900
Message="Syntax error in INSERT INTO statement."
Source="Microsoft JET Database Engine"
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at Tool.clsSQL.AddToDatabase(String TAG, String EquipmentType, String Description, String Status1, String Status2, DateTime DateChanged, String Comments, String UserID) in C:\Documents and Settings\dinoken\My Documents\Visual Studio 2005\Projects\Tool\clsSQL.vb:line 37
Any ideas folks?
If you find my thread helpful, please remember to rate me 
-
Jan 27th, 2010, 11:42 AM
#2
Re: SQL help! What am i doing wrong?
You forgot the closing bracket at the end of the SQL string (your parameter list).
-
Jan 27th, 2010, 12:23 PM
#3
Re: SQL help! What am i doing wrong?
What database are you using?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 27th, 2010, 12:46 PM
#4
Re: SQL help! What am i doing wrong?
As ForumAccount stated, you are missing the closing parenthesis in your Command string:
vb Code:
Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID)", connectionSQL)
Last edited by stateofidleness; Jan 27th, 2010 at 01:06 PM.
-
Jan 27th, 2010, 12:47 PM
#5
Re: SQL help! What am i doing wrong?
 Originally Posted by stateofidleness
As ForumAccount stated, you are missing the closing parenthesis in your Command string:
vb Code:
Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID", connectionSQL))
Wrong place, it's after @UserID that he is missing it.
-
Jan 27th, 2010, 01:02 PM
#6
Re: SQL help! What am i doing wrong?
*sung like Jack Black*
yesss but I was just testing you... ittttt''sssss 999999
heh.
I edited it.
-
Jan 27th, 2010, 01:04 PM
#7
Re: SQL help! What am i doing wrong?
"And that's a magic numberrrr?"
You're not going to like this but its still wrong 
Code:
Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID)", connectionSQL)
-
Jan 27th, 2010, 01:05 PM
#8
Re: SQL help! What am i doing wrong?
well maybe I just like talking to you.
/hate_sql 1
-
Jan 27th, 2010, 01:07 PM
#9
Re: SQL help! What am i doing wrong?
The problem could also be the use of database reserved words for column names... For example, "descriptor" is a reserved word in DB2, ODBC, PostgreSQL 8 and some other DB's. That's why besides the obvious syntax error, you also need to check the field names.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 27th, 2010, 03:48 PM
#10
Thread Starter
Frenzied Member
Re: SQL help! What am i doing wrong?
Ahhh all resolved guys!
Thanks, it was the )
If you find my thread helpful, please remember to rate me 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|