Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data type mismatch in criteria expression

Status
Not open for further replies.

soldierB

Technical User
Dec 11, 2005
37
GB
Hi Guys,

Im stuck with the error
'Data type mismatch in criteria expression'

Can anyone see whats up with this function im trying to make?

The parimeter 'parentid' that is being passed to the function is getting there OK, but as the code gets to
Code:
'---Populate the DataSet

            objDataAdaptor.Fill(objDataSet, "Parents1")

It pops up the messagebox exception error saying "Data type mismatch in criteria expression"

Im passing an integer value to the function, and then in my SQL I query the database field [MainId] which is an autonumbered field type in access itself.

Thanks again
Sb

The function im trying to make is below:
Code:
 Private Function GetParents(ByVal parentid As Integer)
        Dim sSQL As String = _
        "SELECT * FROM main WHERE [MainId] = '" & parentid & "' "

        Dim ParentName As String = ""
        Dim ParentTitle As String = ""
        Dim ParentDOB As String = ""
        Dim ParentFatherID As Integer = 0
        Dim ParentMotherID As Integer = 0

        '---Initialise a new instance of the OleDbConnection class
        objConnection = New OleDbConnection(strConnectionString)
        '---Initialise a new instance of the OleDbCommand class
        objCommand = New OleDbCommand
        '---Set the objCommand object properties
        objCommand.CommandText = sSQL
        objCommand.CommandType = CommandType.Text
        objCommand.Connection = objConnection

        '--- Initialise a new instance of the OleDBDataAdaptor class
        objDataAdaptor = New OleDbDataAdapter
        '---Initialise a new instance of the DataSet class
        objDataSet = New DataSet
        '--- Set the SelectCommand for the OleDbDataAdaptor
        objDataAdaptor.SelectCommand = objCommand

        Try
            '---Populate the DataSet

            objDataAdaptor.Fill(objDataSet, "Parents1")

            ParentName = objDataSet.Tables(0).Rows(0).Item("MName").ToString
            ParentTitle = objDataSet.Tables(0).Rows(0).Item("MTitle")
            ParentDOB = objDataSet.Tables(0).Rows(0).Item("MDOB")
            ParentFatherID = objDataSet.Tables(0).Rows(0).Item("MFatherID")
            ParentMotherID = objDataSet.Tables(0).Rows(0).Item("MMotherID")



        Catch OleDbException As OleDbException
            MessageBox.Show(OleDbException.Message, "Parents1")
        End Try

        '---CleanUp
        objCommand.Dispose()
        objCommand = Nothing
        objDataAdaptor.Dispose()
        objDataAdaptor = Nothing
        objDataSet.Dispose()
        objDataSet = Nothing
        objConnection.Dispose()
        objConnection = Nothing

    End Function
 
Since it's numeric, try removing the single quotes

[tt]"SELECT * FROM main WHERE [MainId] = " & parentid [/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top