开发者

Data type mismatch in criteria expression

I have one porject in VB.NET with 开发者_JAVA技巧Ms Access As Backend...While inserting data into table there is no error at query and Data Type Error,but sometime OleDB Exception occurs Error is"Data type mismatch in criteria expression." the query is ....

Dim cmdstr1 As String = ""
        Dim constr As String = ""
          Dim sqlQuery As String = ""
        constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\PhoneDiary\MyDiary.mdb"

 cmdstr = "Insert Into [DetailData]([ShortName],[Title],[FirstName],[MiddleName],[LastName],[Occupation],[DOB],[Gender],[Country],[State],[Address],[ZipCode],[City],[Memo],[CategoryId],[SubCategoryId],[FavouritesID],[PhotoPath],[vCardPath]) VALUES(aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss)"

  con = New OleDbConnection(constr)
  com = New OleDbCommand(cmdstr, con)
  con.Open()
 com.Parameters.AddWithValue("aa", xx)
 com.Parameters.AddWithValue("bb", cmbTitle.Text)
 com.Parameters.AddWithValue.....
 com.Parameters.AddWithValue....
 .....................
......
 com.ExecuteNonQuery()-------"Data type mismatch in criteria expression"  Here occurs Error

So can u or anybody help me to solve this Problem,please


To the OP, can you post an example of the value of cmdstr when the OleDbException occurs? I suspect mqbt is right and it's probably your DOB field not being able to parse whatever format your DateTime is giving it.

As a related question, is it a good practice to use OleDbCommand.Parameters.AddWithValue to change parameters in a SQL string this way?

I have always built SQL strings in VBA Access just by concatenating the string with the parameters then executing it with Docmd.RunSql(), which seems to suck for long SQL strings with tens of parameters. But it is simple to see the parameters and types. Have I been doing it wrong?


Express your mismatch error in detail, helps to solve in where it throws the issue, for which data type. Otherwise you can check the error in detail on the error throw messagebox

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜