Hi
I need to insert some data from Text boxes in an aspx page into an Access DB but I keep getting a Data type mismatch in criteria expression error.
The problem is the Double which I think I have converted correctly. All the other fields are OK as strings but the value from the Grade TextBox needs to go into a Number field in the Access DB that has been set to Double. Here's my code
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim g As Double
Dim st As String
st = Grade.Text.Trim
g = CDbl(st)
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& Server.MapPath("Test.mdb") & ";"
Dim MySQL As String = "INSERT INTO tblPerson " & _
"(Name, EMail, Webpage, Comments, Age, Birth, Grade) VALUES " & _
"('" & Name.Text & "','" & Email.Text & "','" _
& Webpage.Text & "','" & Comments.Text & "','" _
& Age.Text & "','" & Birth.Text & "'," & g & ")"
Dim MyConn As New Data.OleDb.OleDbConnection(strConn)
Dim cmd As New Data.OleDb.OleDbCommand(MySQL, MyConn)
MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
Response.Redirect("GuestBook.aspx")
End Sub
The code works perfectly without the inclusion of Grade but generates the error when I include Grade.
Thanks
ViRiPuff