|
-
Apr 15th, 2003, 01:08 PM
#1
Thread Starter
Addicted Member
Data type mismatch
I have an error Data type mismatch in criteria expression when I run the application. Below are my codes.
Private Shared mdbPath As String = Application.StartupPath & "\Scholarship.mdb"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath
Dim strSQL As String
Dim rdrEdu As OleDbDataReader
Dim cn As New OleDbConnection(strConn)
cn.Open()
strSQL = "SELECT SSN, Status, HghSchoolGPA, ACT, SAT," & _
"TotalCredits, GPALstSemester, GPACumulative, Rank " & _
"FROM Education WHERE Education.SSN=" & "'" & intSSN & "'"
Dim cmdSQL As New OleDbCommand(strSQL, cn)
Try
rdrEdu = cmdSQL.ExecuteReader
Catch dbException As System.Data.OleDb.OleDbException
MessageBox.Show(dbException.Message)
End Try
Please help.
Many thanks in advance.
Chong
-
Apr 15th, 2003, 01:37 PM
#2
Frenzied Member
If Education.SSN is a numeric filed then omit 's from Education.SSN=" & "'" & intSSN & "'" and let it be :
Education.SSN=" & intSSN
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 15th, 2003, 01:48 PM
#3
Thread Starter
Addicted Member
Thanks for trying to help me.
Yes, the Education.SSN is a number. I did remove the quote around intSSN and here's the error I get:
No value given for one or more required parameters.
Thanks!
Chong
-
Apr 15th, 2003, 02:02 PM
#4
Frenzied Member
check to see if you have spelled all the fields correctly. For example HghSchoolGPA seems to be HighSchoolGPA.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 15th, 2003, 02:22 PM
#5
Thread Starter
Addicted Member
Thanks! Yes, I did misspelled a word. However, because I have changed my SQL query to contain two tables, can I do the following:
Dim strHolder as String
strHolder = "SSN: " & CInt(rdr("Education.SSN")) & " " & rdr("Personal.FstName") & " " & rdr("Personal.MdlName") & " " & rdr("Personal.LstName") & vbCrLf & _
rdr("Personal.Address") & " " & rdr("Personal.StoutCity") & " " & rdr("Personal.StoutState") & " " & rdr("Personal.StoutZip") & vbCrLf & _
"Phone: " & rdr("Personal.StoutPhone") & vbCrLf & _
"Class Standing: " & rdr("Education.Status")
to get the contents out of the tables?
Thanks
-
Apr 15th, 2003, 02:29 PM
#6
Frenzied Member
I guess you can do it.
There is only one point in your code, that i think its not neccessary, and that is:
CInt(rdr("Education.SSN"))
simply use rdr("Education.SSN") and if you want to change type then it should be CStr(rdr("Education.SSN")) as that filed is a number.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 15th, 2003, 02:38 PM
#7
Thread Starter
Addicted Member
I get the following error:
No data exists for the row/column.
Thanks!
Chong
-
Apr 15th, 2003, 02:41 PM
#8
Frenzied Member
The error says all. Check your SQL statement and see if you are returning proper fields.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 15th, 2003, 02:47 PM
#9
Thread Starter
Addicted Member
How would I check to see if I'm returning any value?
Chong
-
Apr 15th, 2003, 02:55 PM
#10
Frenzied Member
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 15th, 2003, 03:01 PM
#11
Thread Starter
Addicted Member
I have simplified my code to this:
Private Shared mdbPath As String = Application.StartupPath & "\Scholarship.mdb"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath
Dim strSQL As String
Dim rdr As OleDbDataReader
Dim cn As New OleDbConnection(strConn)
cn.Open()
strSQL = "SELECT Education.SSN, Education.Status FROM Education WHERE Education.SSN=" & intSSN
Dim cmdSQL As New OleDbCommand(strSQL, cn)
Try
rdr = cmdSQL.ExecuteReader
Catch dbException As System.Data.OleDb.OleDbException
MessageBox.Show(dbException.Message)
End Try
Try
schlrHolder = rdr("SSN")
Catch dbException As Exception
MessageBox.Show(dbException.Message)
End Try
rdr.Close()
By I still received the same error, "No data exists for the row/column."
-
Apr 15th, 2003, 03:14 PM
#12
Frenzied Member
Does this simplifed code throw error? If not send the orginal.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 15th, 2003, 03:18 PM
#13
Thread Starter
Addicted Member
Yes, this simplied version throw an error too. And the error as the same which is "No data exists for the row/column."
Thanks for helping. I'm greatly appreciated!
Chong
-
Apr 15th, 2003, 03:34 PM
#14
Frenzied Member
Its because you have not called the rdr.Read Method before trying to read the data. Remember to close the datareader when done with it.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
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
|