joe_pool_is
Contributor
This is driving me nuts. Code looks good. Database appears to match. SQL statement looks good. Still, I get:
My database is attached, and my code is here:
It bombs on "Command1.ExecuteNonQuery()" every time with the message listed at the top.
Could anyone help me? It's probably a stupid mistake. Maybe a type, but I just can't see it.
Code:
In the Immediate Window:
?sql
"INSERT INTO Legal1 (FirstName, MiddleName, LastName, Date, Signature) VALUES ('Timmy', 'Joe', 'Pool, Jr.', '8/10/2004 5:39:47 PM', 'Poojo');"
?ex.Message
"Syntax error in INSERT INTO statement."
My database is attached, and my code is here:
Code:
Dim i As Integer = 0
Dim strDB As String, strConnection As String
Dim strName() As String
strName = txtPurchaserName.Text.Split(Convert.ToChar(" "))
strDB = Server.MapPath("database.mdb")
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDB & ";Persist Security Info=False"
Select Case UBound(strName, 1)
Case 0 ' // Only one word entered. Used as Last name
SQL = "INSERT INTO Legal1 (LastName, Date, Signature) " & _
"VALUES ('" & strName(0) & "', '" & _
CStr(DateTime.Now) & "', '" & txtPurchaserSign.Text & "');"
Case 1 ' // assumes First and Last names entered
SQL = "INSERT INTO Legal1 (FirstName, LastName, Date, Signature) " & _
"VALUES ('" & strName(0) & "', '" & strName(1) & "', '" & _
CStr(DateTime.Now) & "', '" & txtPurchaserSign.Text & "');"
Case 2 ' // assumes First, Middle, and Last names entered
SQL = "INSERT INTO Legal1 (FirstName, MiddleName, LastName, Date, Signature) " & _
"VALUES ('" & strName(0) & "', '" & strName(1) & "', '" & strName(2) & "', '" & _
CStr(DateTime.Now) & "', '" & txtPurchaserSign.Text & "');"
Case Else ' // assumes First, Middle, Last and prefixes entered
For i = 3 To UBound(strName) ' // appends the rest to the Last name
strName(2) &= " " & strName(i)
Next
SQL = "INSERT INTO Legal1 (FirstName, MiddleName, LastName, Date, Signature) " & _
"VALUES ('" & strName(0) & "', '" & strName(1) & "', '" & strName(2) & "', '" & _
CStr(DateTime.Now) & "', '" & txtPurchaserSign.Text & "');"
End Select
Try
Command1 = New OleDbCommand
Command1.Connection = New OleDbConnection(strConnection)
Command1.Connection.Open()
Command1.CommandText = SQL
Command1.ExecuteNonQuery()
Command1.Connection.Close()
Catch ex As Exception ' // there were errors
Command1.Connection.Close()
lblError.Visible = True
lblError.Text = "Unable to save/update signature and date to database. Please contact Webmaster."
Exit Sub
End Try
Could anyone help me? It's probably a stupid mistake. Maybe a type, but I just can't see it.