[2008] Data type mismatch in criteria expression. [SQL with ACCESS]
Error: Data type mismatch in criteria expression.
Code:
vb Code:
With frmMainMenu
Dim SLen As Integer = Len(.lblCourse.Text)
SLen = SLen - 8
Dim BirthDate As String
Dim GenderChk As String
BirthDate = .txtMonth.Text & "/" & .txtDay.Text & "/" & .txtYear.Text
If .rbMale.Checked = True Then
GenderChk = "Male"
ElseIf .rbFemale.Checked = True Then
GenderChk = "Female"
End If
SQL = "INSERT INTO Course_" & .lblCourse.Text.ToCharArray(8, SLen) & " (LastName, FirstName, Gender, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & GenderChk.ToString() & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate.ToString() & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"
Command = New OleDbCommand(SQL, Connection)
Command.Connection.Open()
Command.ExecuteReader()
Command.Connection.Close()
End With
Mainly This Part:
vb Code:
SQL = "INSERT INTO Course_" & .lblCourse.Text.ToCharArray(8, SLen) & " (LastName, FirstName, Gender, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & GenderChk.ToString() & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate.ToString() & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"
I used
vb Code:
.lblCourse.Text.ToCharArray(8, SLen)
Because I wanted to get the text that appeared after a certain piece of text which then defines the table I'm in.
If I can't use .ToCharArray, what can I do to split the text into 2, and use the last half?
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
.lblCourse.Text.substring(index of first character you want)
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
I'm still getting the same error with this SQL String
vb Code:
SQL = "INSERT INTO Course_" & .lblCourse.Text.Substring(8) & " (LastName, FirstName, Gender, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & GenderChk.ToString() & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate.ToString() & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"
IT then highlights
Command.ExecuteReader()
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
I think
should be Edit: Without Single Quote (')
Also you should have used
Code:
Command.ExecuteNonQuery()
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
Can someone explain what Command.ExecuteReader and Command.ExecuteNonQuery Do? Whats the Difference?
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
Edit: I tried both - tried removing GenderChk (which is a variable to check if its a male or female) but I'm still getting the error:
Heres my new Code
vb Code:
Public Sub InsertIntoStudents()
With frmMainMenu
Dim BirthDate As String
Dim GenderChk As String
BirthDate = .txtMonth.Text & "/" & .txtDay.Text & "/" & .txtYear.Text
If .rbMale.Checked = True Then
GenderChk = "Male"
ElseIf .rbFemale.Checked = True Then
GenderChk = "Female"
End If
Dim i As String = .lblCourse.Text.Substring(8)
SQL = "INSERT INTO Course_ICS3M1" & " (LastName, FirstName, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"
Command = New OleDbCommand(SQL, Connection)
Command.Connection.Open()
Command.ExecuteNonQuery()
Command.Connection.Close()
End With
End Sub
All Fields are filled in on the forum.