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 TouchToneTommy 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.

neegottlob

Programmer
Mar 26, 2006
22
BG
Hello,
what I am trying to do is a dinamyc treeview that take the source form a AccessDatabase. But I recieve that err:
Data type mismatch in criteria expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:


Line 91: Dim titlesForAuthors As New DataSet()
Line 92:
Line 93: adapter.Fill(titlesForAuthors)
Line 94:
Line 95: If titlesForAuthors.Tables.Count > 0 Then


Source File: C:\Documents and Settings\gosho\My Documents\Visual Studio 2005\WebSites\WebSite3\Default2.aspx Line: 93

And here is the part of the Source:

Code:
Private Sub FillTitlesForAuthors(ByVal node As TreeNode)

        Dim CategorID As Integer = node.Value
        Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString
 
        Dim connection As New OleDb.OleDbConnection(connString)
 
        Dim command As New OleDb.OleDbCommand("Select Produkti.ProdID,Produkti.ImeProd From Produkti" + " Inner Join Kategoria on Kategoria.CategorID = Produkti.CategorID " + " Where Kategoria.CategorID = '" + CategorID + "'", connection)
 
        Dim adapter As New OleDb.OleDbDataAdapter(command)
 
        Dim titlesForAuthors As New DataSet()
 
        adapter.Fill(titlesForAuthors)
 
        If titlesForAuthors.Tables.Count > 0 Then
 
            Dim row As DataRow
            For Each row In titlesForAuthors.Tables(0).Rows
                Dim NewNode As TreeNode
                NewNode = New TreeNode(row("ImeProd").ToString(), row("ProdID").ToString())
 
                NewNode.PopulateOnDemand = False
 
                NewNode.SelectAction = TreeNodeSelectAction.None
 
                node.ChildNodes.Add(NewNode)
 
            Next
 
        End If
 
    End

Thanks!
 
Oh I've forgot. I've tried:
Code:
Dim command As New OleDb.OleDbCommand("Select Produkti.ProdID,Produkti.ImeProd From Produkti" + " Inner Join Kategoria on Kategoria.CategorID = Produkti.CategorID " + " Where Kategoria.CategorID = " + CategorID, connection)

And it didn't work Gave mi kind of query problem.I am sure it is in the select.. but I do not know what exactly. Hope somebody has a better ideas :eek:
 
neegottlob: Is your ID a number? If so the following:


Kategoria.CategorID = '" + CategorID + "'"

..suggests a string, perhaps try:

Kategoria.CategorID =" + CategorID
 
I Solved the problem. It was in the select I've jumped one table over in the relationship and now it is ok. Thank you!
 
but now it happens something strange:
for example a node in Depth=1 has 2 child nodes it double the Parent node too, o if they are tree so it makes 3 parent nodes with tha same name.. Any Idea why is that?:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top