asp.net - Adding Session Variable as OleDbParameter - running into error " -
i using custom asp.net control found here: http://www.codeproject.com/articles/5347/datacalendar
i have used 1 of templates in source file download-able page above starting point custom calendar. aim display events current user has created. doing creating session variable called "username" , parameterizing in query so:
function geteventdata(startdate datetime, enddate datetime) datatable '--read data access query dim con oledbconnection = getconnection() dim cmd oledbcommand = new oledbcommand() cmd.connection = con cmd.parameters.addwithvalue("@currentuser", session("currentuser")) cmd.commandtext = string.format("select eventdate, createdby, count(*) eventinfo (createdby = @currentuser) , eventdate >= #{0}# , eventdate <= #{1}# group eventdate", _ startdate, enddate) dim ds dataset = new dataset() dim da oledbdataadapter = new oledbdataadapter(cmd) da.fill(ds) con.close() return ds.tables(0) end function
unfortunately receiving error:
parameter[0] '' has no default value.
i have ensured logged in not problem of there being no value user.identity.name (i don't think). creating session variable in page load sub:
sub page_load(o object, e eventargs) session("currentuser") = user.identity.name end sub
so, what's going wrong?
from msdn :
the ole db.net provider not support named parameters passing parameters sql statement or stored procedure called oledbcommand when commandtype set text. in case, question mark (?) placeholder must used. example:
select * customers customerid = ?
therefore, order in oledbparameter objects added oledbparametercollection must directly correspond position of question mark placeholder parameter.
try:
cmd.commandtext = string.format("select eventdate, createdby, count(*) eventinfo ([createdby = ?]) , eventdate >= #{0}# , eventdate <= #{1}# group eventdate,createdby", startdate, enddate)
Comments
Post a Comment