开发者

ADO LIKE query in ASP (vbs)

I have a query like this:

SELECT TaFellesVaktjournal.*, TaBygg.ByggNavn
FROM TaFellesVaktjournal LEFT JOIN TaBygg ON
TaFellesVaktjournal.VaktFellesByggNavnId =
Ta开发者_如何学GoBygg.ByggBudsjtilstEiendom WHERE VaktjFellesDato
>= @dtfr AND VaktjFellesDato <= @dttl AND (VaktFellesSak
= @sok OR VaktjFellesHendelse = @sok) ORDER BY
VaktjFellesDato DESC, VaktjFellesTid DESC

However, I get an error stating that No value given for one or more required parameters.. I've specified values for @dtfr, @dttl and @sok. Also, the error goes away if I remove the parts containing @sok (everything after @dttl) to the ORDER BY.

I've made shure I specify values for sok, and that it's not empty. I've even tried specifing 2 parameters named sok (since they are two places). Anyone know how I can do this?

The code I use to create parameters is as following:

Dim conn, cmd, param
set cmd = server.createobject("adodb.command")
set param = server.createobject("adodb.parameter")
set param = cmd.createparameter("@sok", adVarChar, adParamInput, 255, sok)
cmd.parameters.append param


it will work for "normal" sql statements similiar like it works for storedprocedures. you have to set the CommandType property of the command object to adCmdText for "normal" sql statements AND you have to you use q questionmark "?" instead of parameter names.

you do not need the refresh method ado will do that automatically for you. (it is only useful for stored procedures either)

dim sql
dim cmd : set cmd = server.createObject("ADODB.Command")
dim param, rs

sql = "SELECT TaFellesVaktjournal.*, TaBygg.ByggNavn" &_
      " FROM TaFellesVaktjournal" &_
      " LEFT JOIN TaBygg ON TaFellesVaktjournal.VaktFellesByggNavnId = TaBygg.ByggBudsjtilstEiendom" &_
      " WHERE VaktjFellesDato >= ?" &_
      " AND VaktjFellesDato <= ?" &_
      " AND (VaktFellesSak= ? OR VaktjFellesHendelse = ?)" &_
      " ORDER BY VaktjFellesDato DESC, VaktjFellesTid DESC"

cmd.ActiveConnection = conn
cmd.CommandType = adCmdText

set param = cmd.CreateParameter("dtfr", adVarChar, , 255, dtfr)
cmd.Parameters.Append param

set param = cmd.CreateParameter("dtfr2", adVarChar, , 255, dtfr)
cmd.Parameters.Append param

set param = cmd.CreateParameter("dttl", adVarChar, , 255, dttl)
cmd.Parameters.Append param

set param = cmd.CreateParameter("sok", adVarChar, , 255, sok)
cmd.Parameters.Append param

cmd.CommandText = sql

set rs = cmd.execute

set param = nothing
set cmd = nothing


You can try populating the Parameter collection using a refresh command.

Set cmd.ActiveConnection = oConn
oCmd.CommandType=adCmdStoredProc
oCmd.CommandText="ap_Your_spName"
oCmd.Parameters.Refresh
oCmd.Parameters("@dtfr") = dtfr
oCmd.Parameters("@dttl") = dttl
oCmd.Parameters("@sok") = sok
oCmd.Execute

Will incur a round trip to the server, but modern computers should cope with it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜