sql - Data type mismatch when inserting record -
i've piece of code inserting records access table.
lastupdated
field defined date/time
@ database level. fails when inserting giving error
data type mismatch in criteria expression
i'm using parameterized query avoid problems formatting values , it's weird because i've same code (with more parameters) insert records on table on lastupdated
defined in same way , it's working fine.
any idea?
sqlquery = "insert history (activityid, lastupdated) values (@p1,@p2)" sqlcommand .commandtext = sqlquery .connection = sqlconnection .parameters.addwithvalue("@p1", idact) .parameters.addwithvalue("@p2", datetime.today) end result = sqlcommand.executenonquery() if (result = 1) labelwarning.text = "activity filled" labelwarning.backcolor = color.forestgreen labelwarning.visible = true buttonsave.visible = false buttonback.visible = false buttonok.visible = true blockcontrols() end if
maybe problem linked parameter placeholder.
this msdn doc states oledbcommand not support named parameter (only positional) , correct placeholder should "?" , not "@p1".
https://msdn.microsoft.com/en-us/library/yy6y35y8%28v=vs.110%29.aspx
edit
it turned out in comments placeholder have not strictly adherent doc syntax. order has absolutely preserved.
explicitly declaring parameter type seemed trick:
.parameters.add("@p2", oledbtype.dbtimestamp) .parameters("@p2").value = datetime.today
Comments
Post a Comment