oledb - Updating an MsAccess database that has Short Text and Number type of fields in VB.net -


i have textboxes , want update database using these textboxes. have tried removing ' ' symbols in regular , ot database field in query still keep getting error when press button:

an unhandled exception of type 'system.data.oledb.oledbexception' occurred in system.data.dll  additional information: data type mismatch in criteria expression. 

note: regular , ot field both number types in database whilst evertything short text.

this oledb statement:

"update datana set today = '" & datestring & "',  projectcode = '" & prjctcodepasslbl.text & "',  project = '" & prjctnametxtbox.text & "',  mark = '" & marktxtbox.text & "',  activity = '" & actvtytxtbox.text & "',  regular = '" & integer.parse(rglrtxtbox.text) & "',  ot = '" & integer.parse(ottxtbox.text) & "'   today = '" & datelbl.text & "' , projectcode = '" & prjctcodepasslbl.text & "'  , project = '" & prjctnamelbl.text & "'  , mark = '" & marklbl.text & "'  , activity = '" & actvtylbl.text & "'  , regular = '" & rglrlbl.text & "'  , ot = '" & otlbl.text & "' " 

you should use parameterized query specifying datatype of every parameter add query. in way db engine knows how handle values , assign them query appropriate quotes when required.

i give example (incomplete should give valid starting point)

dim sql = "update datana set today = @dt, " & _           "projectcode = @pcode, " & _           "project = @prj, " & _           "mark = @mark, " & _           "activity = @activity, " & _           "regular = @regular, " & _           "ot = @ot " & _           "where today = @dt1 , projectcode = @pcode1 " & _           "and project = @prj1 "&             "and mark = @mark1 " & _           "and activity = @activity1 " & _           "and regular = @regular1 " & _           "and ot = @ot1 "  using cnn = new oledbconnection(... connectionstring here....)  using cmd = new oledbcommand(sql, cnn)      cnn.open()      cmd          .parameters.add("@dt", oledbtype.varwchar).value = datestring           .parameters.add("@pcode", oledbtype.varwchar).value = prjctcodepasslbl.text           ... , on other parameters...          ... remember oledb need add them           ... parameters collection in same exact order           ... in appear in sql string.          ... of course every parameter should have correct           ... oledbtype expected table, example          .parameters.add("@regular", oledbtype.integer).value = integer.parse(rglrtxtbox.text)          ... call      end      cmd.executenonquery  end using  end using 

check oledbtype enum here

probably error caused putting quotes around values 2 integers value both in update , in clause. in case parameterized query avoid these mishaps.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -