Click here to Skip to main content
15,742,150 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900