hi guys... i am having problem when adding stuff in the database.i included the three functions that am using to add the data to the database. The connection is working fine so don't worry about it. its the probably the syntax of some code that is not working correctly. The line in red is where the compiler is complaining about.
here is the error that i get:
incorrect syntax near ')'. at
system.sql.data.sqlconnection.on error(.....)
at system.data.sqlclient.internalconnection.onerror(...)
at system.data.sqlclient.tsdParser.throwexceptionandWarning()
at system.data.tsqlclient.sdparser.run(...)
at system.data.sqlclient.sqlcommand.internalExecutionnonQueryTsd(...)
Protected Function UpdateDataSource(ByVal currentCommand As SqlCommand) As Boolean
Dim success As Boolean = False
Try
'open the connection
cnMain.Open()
currentCommand.CommandType = CommandType.Text
currentCommand.ExecuteNonQuery() ' am having the problem here
'close the connection
cnMain.Close()
success = True
Catch errObj As Exception
MessageBox.Show(errObj.Message & " " & errObj.StackTrace)
Finally
End Try
Return success
End Function
Public Sub DatabaseAdd(ByVal TempGuest As Guest)
Dim strSQL As String = ""
strSQL = "INSERT into Runner(GuestID, GuestName, GuestSurname, GuestDOB, GuestGender, GuestAddress, GuestPostalcode, GuestPhone, GuestEmail)" & _
"VALUES ('" & GetValueString(TempGuest) & ")"
'Create & execute the insert command
UpdateDataSource(New SqlCommand(strSQL, cnMain))
End Sub
Private Function GetValueString(ByVal TempGuest As Guest) As String
Dim aStr As String = ""
aStr = TempGuest.GuestID & "' , '" & TempGuest.GuestName & "' ," & _
"' " & TempGuest.GuestSurname & " ' ," & _
"'" & TempGuest.DOB & "' , " & _
"'" & TempGuest.Gender & " ' ," & _
"'" & TempGuest.Address & " ' ," & _
"'" & TempGuest.PostalCode & " ' ," & _
"'" & TempGuest.PhoneNumber & " ' ," & _
"' " & TempGuest.Email & "' , "
Return aStr
End Function
here is the error that i get:
incorrect syntax near ')'. at
system.sql.data.sqlconnection.on error(.....)
at system.data.sqlclient.internalconnection.onerror(...)
at system.data.sqlclient.tsdParser.throwexceptionandWarning()
at system.data.tsqlclient.sdparser.run(...)
at system.data.sqlclient.sqlcommand.internalExecutionnonQueryTsd(...)
Protected Function UpdateDataSource(ByVal currentCommand As SqlCommand) As Boolean
Dim success As Boolean = False
Try
'open the connection
cnMain.Open()
currentCommand.CommandType = CommandType.Text
currentCommand.ExecuteNonQuery() ' am having the problem here
'close the connection
cnMain.Close()
success = True
Catch errObj As Exception
MessageBox.Show(errObj.Message & " " & errObj.StackTrace)
Finally
End Try
Return success
End Function
Public Sub DatabaseAdd(ByVal TempGuest As Guest)
Dim strSQL As String = ""
strSQL = "INSERT into Runner(GuestID, GuestName, GuestSurname, GuestDOB, GuestGender, GuestAddress, GuestPostalcode, GuestPhone, GuestEmail)" & _
"VALUES ('" & GetValueString(TempGuest) & ")"
'Create & execute the insert command
UpdateDataSource(New SqlCommand(strSQL, cnMain))
End Sub
Private Function GetValueString(ByVal TempGuest As Guest) As String
Dim aStr As String = ""
aStr = TempGuest.GuestID & "' , '" & TempGuest.GuestName & "' ," & _
"' " & TempGuest.GuestSurname & " ' ," & _
"'" & TempGuest.DOB & "' , " & _
"'" & TempGuest.Gender & " ' ," & _
"'" & TempGuest.Address & " ' ," & _
"'" & TempGuest.PostalCode & " ' ," & _
"'" & TempGuest.PhoneNumber & " ' ," & _
"' " & TempGuest.Email & "' , "
Return aStr
End Function