6 Replies - 1143 Views - Last Post: 02 May 2013 - 05:43 AM Rate Topic: -----

#1 VB ASRAAF007   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Data Type mismatch in criteria expression

Posted 02 May 2013 - 04:47 AM

Hello im facing a problem with the data type mismatch in criteria expression here are my codes

        Sql = "delete * from employeeDetails where employee_ID='" & employee_id_txt.Text & "'"
        Dim acscmd As New OleDb.OleDbCommand
        acscmd.CommandText = Sql
        acscmd.Connection = con
        acscmd.ExecuteNonQuery()
        acscmd.Dispose()
        MsgBox("Records deleted")
        Me.fillListViewEmployee()


Attached image(s)

  • Attached Image

This post has been edited by VB ASRAAF007: 02 May 2013 - 04:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Data Type mismatch in criteria expression

#2 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Data Type mismatch in criteria expression

Posted 02 May 2013 - 04:49 AM

Numeric fields (including Autonumber) fields which a lot of ID's typically are, should not be wrapped with apostrophes. Those are reserved to denote text and in some databases, date fields.

Learn to create parameterized statement. This would alleviate 90% of this problem along with making your database contents more secure against SQL injection.

This post has been edited by CharlieMay: 02 May 2013 - 04:50 AM

Was This Post Helpful? 0
  • +
  • -

#3 vks.gautam1   User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 21-March 08

Re: Data Type mismatch in criteria expression

Posted 02 May 2013 - 04:54 AM

well this is right one..second thing you should study about parametrs
Sql = "delete  from employeeDetails where employee_ID='" & employee_id_txt.Text & "




check last post from below of page where you will get to know about parameters in sqlquery with vb.net
http://www.dreaminco...s-in-sql-query/


make "Option Strict On" above your form code

This post has been edited by vks.gautam1: 02 May 2013 - 05:00 AM

Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Data Type mismatch in criteria expression

Posted 02 May 2013 - 05:13 AM

View Postvks.gautam1, on 02 May 2013 - 07:54 AM, said:

well this is right one..second thing you should study about parametrs
Sql = "delete  from employeeDetails where employee_ID='" & employee_id_txt.Text & "


NOPE!! Recheck that code segment there vks.gautam1
Was This Post Helpful? 0
  • +
  • -

#5 vks.gautam1   User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 21-March 08

Re: Data Type mismatch in criteria expression

Posted 02 May 2013 - 05:32 AM

View PostCharlieMay, on 02 May 2013 - 05:13 AM, said:

View Postvks.gautam1, on 02 May 2013 - 07:54 AM, said:

well this is right one..second thing you should study about parametrs
Sql = "delete  from employeeDetails where employee_ID='" & employee_id_txt.Text & "


NOPE!! Recheck that code segment there vks.gautam1


ogh ya he is not convert string to integer. lol sorry i answered him off the topic more.

when he pass value to parameter in sql command he should use cint function for this
delete  from employeeDetails where [email protected]
command.parametrs add with value("@empid",cint(textbox1.text)


hope so im right this time perfectly

This post has been edited by vks.gautam1: 02 May 2013 - 05:33 AM

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Data Type mismatch in criteria expression

Posted 02 May 2013 - 05:41 AM

Nope again.

I was talking about
Sql = "delete  from employeeDetails where employee_ID='" & employee_id_txt.Text & "
                                                      ^                         ^ ^

Of course the parameter version would work but the original concatenated string you supplied still had errors and that's what I was pointing out.

Actually Parametrs and Add With Value ?????

Anyway, I got the jist of your solution but don't know if someone just learning would find it easy to run and test.

This post has been edited by CharlieMay: 02 May 2013 - 05:44 AM

Was This Post Helpful? 1
  • +
  • -

#7 vks.gautam1   User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 21-March 08

Re: Data Type mismatch in criteria expression

Posted 02 May 2013 - 05:43 AM

View PostCharlieMay, on 02 May 2013 - 05:41 AM, said:

Nope again.

I was talking about
Sql = "delete  from employeeDetails where employee_ID='" & employee_id_txt.Text & "
                                                      ^                         ^ ^

Of course the parameter version would work but the original concatenated string you supplied still had errors and that's what I was pointing out.

ohh ok now i understand ..thnx for pointing out
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1