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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -