Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
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
VB
Private Sub imageshow()
        con.Open()
        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
        con.Close()
    End Sub


please help me sir m not getting any thing

hear is the image
http://tinypic.com/r/15s6dg9/6[^]
Posted
Updated 26-Oct-12 21:42pm
v2

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