vb.net - Adding SQL Parameter fails -


this new concept me , can't quite see what's causing error i'm attempting populate datagridview control single field in access database (from combo , text box source). using literals works, not parameter.

dim conn new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=" & backend & ";persist security info=false;")     dim command new oledbcommand("select year tbltest ", conn)     dim criteria new list(of string)      if not cboyear.text = string.empty         criteria.add("year = @year")         command.parameters.addwithvalue("@year", cboyear.text)     end if      if criteria.count > 0         command.commandtext &= " " & string.join(" , ", criteria)     end if      dim userquery new oledbdataadapter(command.commandtext, conn)     dim userret new datatable     userquery.fill(userret)      frmdgv.datagridview2         .datasource = userret     end      frmdgv.datagridview2.visible = true     frmdgv.show() 

trying fill datatable shows exception 'no value given 1 or more required parameters.'

the value of command.commandtext @ point "select year tbltest year = @year"

your instance of oledbdataadapter created using 2 parameters query text , connection.

dim userquery new oledbdataadapter(command.commandtext, conn) 

in case dataadapter doesn't know parameters @ all.

instead use constructor paremeter of type oledbcommand.

dim userquery new oledbdataadapter(command) 

in code instance of oledbcommand associated connection


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -