Click here to Skip to main content
14,301,895 members
Rate this:
Please Sign up or sign in to vote.
See more:
sir am inserting image path in ms access database inserted successfully but when am trying to update or display image its always saying that Data type mismatch in criteria expression
hear is my code
Private Sub imageshow()
        Dim cmd As New OleDbCommand("select alumni_imagepath from alumnidata where sl1='" & txtsl.Text & "'", con)
        Dim path As String = cmd.ExecuteScalar().ToString()
        ImageMap1.ImageUrl = path
    End Sub

please help me sir m not getting any thing

hear is the image[^]
Updated 26-Oct-12 21:42pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

What it is complaining about is the WHERE clause: the "criteria expression".

Firstly, look at the content of txtsl.Text - what is it? Compare that with the datatype of the column "sl1" - because that is what SQL is trying to convert it to. So if txtsl.Text is "Hello" and "sl1" is an integer field, it is going to complain that it can't convert the string to an integer.

Secondly, don't ever do that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100