|
-
Sep 12th, 2008, 03:34 PM
#1
Thread Starter
Hyperactive Member
[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?
-
Sep 12th, 2008, 03:51 PM
#2
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
.lblCourse.Text.substring(index of first character you want)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 12th, 2008, 03:53 PM
#3
Thread Starter
Hyperactive Member
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()
-
Sep 12th, 2008, 04:49 PM
#4
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()
Last edited by riteshjain1982; Sep 12th, 2008 at 04:57 PM.
__________________
Rate the posts that helped you 
-
Sep 12th, 2008, 05:17 PM
#5
Thread Starter
Hyperactive Member
Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]
Can someone explain what Command.ExecuteReader and Command.ExecuteNonQuery Do? Whats the Difference?
-
Sep 12th, 2008, 05:22 PM
#6
Thread Starter
Hyperactive Member
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.
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
|