Ask a Question related to ASP Database, Design and Development.
-
Serge Myrand #1
Convention for writing parameters in CommandText
Hi,
This function always return and empty RecordSet (R.eof=True) the problem
is probably the way I pass the parameter in the CommandText. To avoid
looking at all code first look at this I think my mistake is
'[@prmClientNo]' but it does not give any error message. Any help will
be appreciate!
// code from the function below
Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS c
" & _
"LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO = cr.CLIENT_NO "
& _
"WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
"ORDER BY NAME ASC", conn, adOpenForwardOnly,
adLockReadOnly, _
adCmdText)
//************************************************** ********************************
function ClientNoIsValid(sClientNo)
dim conn
dim R
dim F
dim prm
dim cmd
set conn = Server.CreateObject("ADODB.Connection")
set R = server.CreateObject("ADODB.RecordSet")
set cmd = Server.CreateObject("ADODB.Command")
conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;Data Source=" &
_
Server.MapPath("Data\WEB_PROD.mdb") & ";Persist
Security Info=True"
conn.CursorLocation=adUseClient
conn.Mode= adModeRead
conn.Open
Set cmd.ActiveConnection = Conn
set prm = cmd.CreateParameter("@prmClientNo", adChar, adParamInput, 13)
cmd.Parameters.Append prm
cmd.Parameters("@prmClientNo").Value = sClientNo
cmd.Parameters.Refresh
R.CursorLocation=adUseClient
Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS c
" & _
"LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO = cr.CLIENT_NO "
& _
"WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
"ORDER BY NAME ASC", conn, adOpenForwardOnly,
adLockReadOnly, _
adCmdText)
ClientNoIsValid = not R.eof
Response.Write R.eof & "<br>"
'Response.Write R.Fields("COMP_NAME").Value & " " &
R.Fields("NAME").Value & "<BR>"
Set conn = Nothing
Set R = Nothing
end function
//*******************************
Thank's in advance
serge
Serge Myrand Guest
-
Writing a DIV tag?
Starting to mess with writing to the HtmlTextWriter, and have a question about divs. Why is it that HtmlTextWriterTag.Div writes a *table*, when... -
build CommandText string->error!!!
your sqlcmd is out of scope, once you closed the } all the information about the sqlcmd is dumped and no reference to it exists -
Writing to jpg fix?
I just switched from Quark. Now when I'm placing any kind of graphic (pdf or tiff), when In Design places the graphic, a dialog box comes up that... -
Website File Naming Convention-Pub2003
Have no problem loading website to ISP. Publisher names each page of the website index_page561xxx.htm, etc. How do I get it to name the page by... -
create parameters without creating parameters
cant you create ado command parameteres without creating a parameter object? i have a function that takes the name of a stored proc, and two... -
Serge Myrand #2
Re: Convention for writing parameters in CommandText
Thank you very much,
I will use 'saved parameter query' when I will be able to do everything by hand.
"Bob Barrows [MVP]" wrote:
> Serge Myrand wrote:>> > Hi,
> >
> > This function always return and empty RecordSet (R.eof=True) the
> > problem
> > is probably the way I pass the parameter in the CommandText. To avoid
> > looking at all code first look at this I think my mistake is
> > '[@prmClientNo]'
> True.
> When using a text sql statement, you have to use the ODBC ? parameter
> placeholder, like this:.
>
> sSQL = "SELECT ... WHERE c.CLIENT_NO = ? ..."
>> You just undid all of your hard work in building the Command object. See> > but it does not give any error message. Any help will
> > be appreciate!
> >
> > // code from the function below
> > Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS
> > c " & _
> > "LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO =
> > cr.CLIENT_NO " & _
> > "WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
> > "ORDER BY NAME ASC", conn, adOpenForwardOnly,
> > adLockReadOnly, _
> > adCmdText)
> >
> below
>> //************************************************** ************************> >
> >
> ********>> >
> > function ClientNoIsValid(sClientNo)
> > dim conn
> > dim R
> > dim F
> > dim prm
> > dim cmd
> > set conn = Server.CreateObject("ADODB.Connection")
> > set R = server.CreateObject("ADODB.RecordSet")
> > set cmd = Server.CreateObject("ADODB.Command")
> >
> > conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;Data
> > Source=" & _
> > Server.MapPath("Data\WEB_PROD.mdb") & ";Persist
> > Security Info=True"
> > conn.CursorLocation=adUseClient
> > conn.Mode= adModeRead
> > conn.Open
> > Set cmd.ActiveConnection = Conn
> > set prm = cmd.CreateParameter("@prmClientNo", adChar, adParamInput,
> > 13)
> >
> > cmd.Parameters.Append prm
> > cmd.Parameters("@prmClientNo").Value = sClientNo
> NO! Get rid of the following line:
> ************************************> **************************************> > cmd.Parameters.Refresh>> >
> > R.CursorLocation=adUseClient
> I look at the following and all I can say is: "Incredible!" Why did you
> build the Command object if you weren't going to use it??
>>> > Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS
> > c " & _
> > "LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO =
> > cr.CLIENT_NO " & _
> > "WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
> > "ORDER BY NAME ASC", conn, adOpenForwardOnly,
> > adLockReadOnly, _
> > adCmdText)
> 1) Since you are using a client-side cursor, the only cursor-type available
> is a static cursor. If you really want a forward-only cursor (and it appears
> that you do), you need to get rid of the lines where you set the
> cursorlocation to adUseClient.
>
> Let's modify your code as follows:
>
> dim conn
> dim R
> dim F 'What is this?
> dim sSQL
> dim prm
> dim cmd
> sSQL = "SELECT ... WHERE c.CLIENT_NO = ? ..."
> set conn = Server.CreateObject("ADODB.Connection")
> conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;" & _
> "Data Source=" & Server.MapPath("Data\WEB_PROD.mdb")
> conn.Open
> set cmd = Server.CreateObject("ADODB.Command")
> Set cmd.ActiveConnection = Conn
> cmd.CommandText = sSQL
> cmd.CommandType=adCmdText
> set prm = cmd.CreateParameter("@prmClientNo", adVarChar, _
> adParamInput, 13)
> cmd.Parameters.Append prm
> cmd.Parameters("@prmClientNo").Value = sClientNo
>
> Set R = cmd.Execute
>>> > ClientNoIsValid = not R.eof
> > Response.Write R.eof & "<br>"
> > 'Response.Write R.Fields("COMP_NAME").Value & " " &
> > R.Fields("NAME").Value & "<BR>"
> > Set conn = Nothing
> > Set R = Nothing
> >
> > end function
> >
> By not using a saved parameter query, you are making life difficult for
> youself. Do yourself a favor and Google for posts by me containing the words
> "saved parameter query".
>
> Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.Serge Myrand Guest
-
Serge Myrand #3
Re: Convention for writing parameters in CommandText
Everythings works find now.
If I had many parameters would I "Append" them in the order the query will use
them and still use the '?' as placeholder in the CommandText?
thank's
serge
"Bob Barrows [MVP]" wrote:
> Serge Myrand wrote:>> > Hi,
> >
> > This function always return and empty RecordSet (R.eof=True) the
> > problem
> > is probably the way I pass the parameter in the CommandText. To avoid
> > looking at all code first look at this I think my mistake is
> > '[@prmClientNo]'
> True.
> When using a text sql statement, you have to use the ODBC ? parameter
> placeholder, like this:.
>
> sSQL = "SELECT ... WHERE c.CLIENT_NO = ? ..."
>> You just undid all of your hard work in building the Command object. See> > but it does not give any error message. Any help will
> > be appreciate!
> >
> > // code from the function below
> > Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS
> > c " & _
> > "LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO =
> > cr.CLIENT_NO " & _
> > "WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
> > "ORDER BY NAME ASC", conn, adOpenForwardOnly,
> > adLockReadOnly, _
> > adCmdText)
> >
> below
>> //************************************************** ************************> >
> >
> ********>> >
> > function ClientNoIsValid(sClientNo)
> > dim conn
> > dim R
> > dim F
> > dim prm
> > dim cmd
> > set conn = Server.CreateObject("ADODB.Connection")
> > set R = server.CreateObject("ADODB.RecordSet")
> > set cmd = Server.CreateObject("ADODB.Command")
> >
> > conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;Data
> > Source=" & _
> > Server.MapPath("Data\WEB_PROD.mdb") & ";Persist
> > Security Info=True"
> > conn.CursorLocation=adUseClient
> > conn.Mode= adModeRead
> > conn.Open
> > Set cmd.ActiveConnection = Conn
> > set prm = cmd.CreateParameter("@prmClientNo", adChar, adParamInput,
> > 13)
> >
> > cmd.Parameters.Append prm
> > cmd.Parameters("@prmClientNo").Value = sClientNo
> NO! Get rid of the following line:
> ************************************> **************************************> > cmd.Parameters.Refresh>> >
> > R.CursorLocation=adUseClient
> I look at the following and all I can say is: "Incredible!" Why did you
> build the Command object if you weren't going to use it??
>>> > Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS
> > c " & _
> > "LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO =
> > cr.CLIENT_NO " & _
> > "WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
> > "ORDER BY NAME ASC", conn, adOpenForwardOnly,
> > adLockReadOnly, _
> > adCmdText)
> 1) Since you are using a client-side cursor, the only cursor-type available
> is a static cursor. If you really want a forward-only cursor (and it appears
> that you do), you need to get rid of the lines where you set the
> cursorlocation to adUseClient.
>
> Let's modify your code as follows:
>
> dim conn
> dim R
> dim F 'What is this?
> dim sSQL
> dim prm
> dim cmd
> sSQL = "SELECT ... WHERE c.CLIENT_NO = ? ..."
> set conn = Server.CreateObject("ADODB.Connection")
> conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;" & _
> "Data Source=" & Server.MapPath("Data\WEB_PROD.mdb")
> conn.Open
> set cmd = Server.CreateObject("ADODB.Command")
> Set cmd.ActiveConnection = Conn
> cmd.CommandText = sSQL
> cmd.CommandType=adCmdText
> set prm = cmd.CreateParameter("@prmClientNo", adVarChar, _
> adParamInput, 13)
> cmd.Parameters.Append prm
> cmd.Parameters("@prmClientNo").Value = sClientNo
>
> Set R = cmd.Execute
>>> > ClientNoIsValid = not R.eof
> > Response.Write R.eof & "<br>"
> > 'Response.Write R.Fields("COMP_NAME").Value & " " &
> > R.Fields("NAME").Value & "<BR>"
> > Set conn = Nothing
> > Set R = Nothing
> >
> > end function
> >
> By not using a saved parameter query, you are making life difficult for
> youself. Do yourself a favor and Google for posts by me containing the words
> "saved parameter query".
>
> Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.Serge Myrand Guest
-
Bob Barrows [MVP] #4
Re: Convention for writing parameters in CommandText
Serge Myrand wrote:
True.> Hi,
>
> This function always return and empty RecordSet (R.eof=True) the
> problem
> is probably the way I pass the parameter in the CommandText. To avoid
> looking at all code first look at this I think my mistake is
> '[@prmClientNo]'
When using a text sql statement, you have to use the ODBC ? parameter
placeholder, like this:.
sSQL = "SELECT ... WHERE c.CLIENT_NO = ? ..."
You just undid all of your hard work in building the Command object. See> but it does not give any error message. Any help will
> be appreciate!
>
> // code from the function below
> Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS
> c " & _
> "LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO =
> cr.CLIENT_NO " & _
> "WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
> "ORDER BY NAME ASC", conn, adOpenForwardOnly,
> adLockReadOnly, _
> adCmdText)
>
below
//************************************************** ************************>
>
********>
> function ClientNoIsValid(sClientNo)
> dim conn
> dim R
> dim F
> dim prm
> dim cmd
> set conn = Server.CreateObject("ADODB.Connection")
> set R = server.CreateObject("ADODB.RecordSet")
> set cmd = Server.CreateObject("ADODB.Command")
>
> conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;Data
> Source=" & _
> Server.MapPath("Data\WEB_PROD.mdb") & ";Persist
> Security Info=True"
> conn.CursorLocation=adUseClient
> conn.Mode= adModeRead
> conn.Open
> Set cmd.ActiveConnection = Conn
> set prm = cmd.CreateParameter("@prmClientNo", adChar, adParamInput,
> 13)
>
> cmd.Parameters.Append prm
> cmd.Parameters("@prmClientNo").Value = sClientNo
NO! Get rid of the following line:
**************************************************************************> cmd.Parameters.RefreshI look at the following and all I can say is: "Incredible!" Why did you>
> R.CursorLocation=adUseClient
build the Command object if you weren't going to use it??
1) Since you are using a client-side cursor, the only cursor-type available> Call R.Open("SELECT c.COMP_NAME, c.CLIENT_NO, cr.NAME FROM CLIENT AS
> c " & _
> "LEFT JOIN CLIENT_REF AS cr ON c.CLIENT_NO =
> cr.CLIENT_NO " & _
> "WHERE c.CLIENT_NO = '[@prmClientNo]' " & _
> "ORDER BY NAME ASC", conn, adOpenForwardOnly,
> adLockReadOnly, _
> adCmdText)
is a static cursor. If you really want a forward-only cursor (and it appears
that you do), you need to get rid of the lines where you set the
cursorlocation to adUseClient.
Let's modify your code as follows:
dim conn
dim R
dim F 'What is this?
dim sSQL
dim prm
dim cmd
sSQL = "SELECT ... WHERE c.CLIENT_NO = ? ..."
set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString="Provider=Microsoft.Jet.OLED B.4.0;" & _
"Data Source=" & Server.MapPath("Data\WEB_PROD.mdb")
conn.Open
set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = Conn
cmd.CommandText = sSQL
cmd.CommandType=adCmdText
set prm = cmd.CreateParameter("@prmClientNo", adVarChar, _
adParamInput, 13)
cmd.Parameters.Append prm
cmd.Parameters("@prmClientNo").Value = sClientNo
Set R = cmd.Execute
By not using a saved parameter query, you are making life difficult for> ClientNoIsValid = not R.eof
> Response.Write R.eof & "<br>"
> 'Response.Write R.Fields("COMP_NAME").Value & " " &
> R.Fields("NAME").Value & "<BR>"
> Set conn = Nothing
> Set R = Nothing
>
> end function
>
youself. Do yourself a favor and Google for posts by me containing the words
"saved parameter query".
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Aaron [SQL Server MVP] #5
Re: Convention for writing parameters in CommandText
> If I had many parameters would I "Append" them in the order the query
will useWouldn't it be a bit more sane and manageable to use named parameters?> them and still use the '?' as placeholder in the CommandText?
Doesn't Bob have a script that will automate the creation of this?
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
Aaron [SQL Server MVP] Guest
-
Bob Barrows [MVP] #6
Re: Convention for writing parameters in CommandText
Serge Myrand wrote:
Yes. But it would be MUCH simpler to use saved parameter queries.> Everythings works find now.
>
> If I had many parameters would I "Append" them in the order the
> query will use them and still use the '?' as placeholder in the
> CommandText?
>
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Bob Barrows [MVP] #7
Re: Convention for writing parameters in CommandText
Aaron [SQL Server MVP] wrote:
Unfortunately, he's using Access, so my code generator won't work for that.>>> If I had many parameters would I "Append" them in the order the
>> query will use them and still use the '?' as placeholder in the
>> CommandText?
> Wouldn't it be a bit more sane and manageable to use named parameters?
> Doesn't Bob have a script that will automate the creation of this?
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Serge Myrand #8
Re: Convention for writing parameters in CommandText
Ok, Thank you for your time.
serge
"Bob Barrows [MVP]" wrote:
> Serge Myrand wrote:>> > Everythings works find now.
> >
> > If I had many parameters would I "Append" them in the order the
> > query will use them and still use the '?' as placeholder in the
> > CommandText?
> >
> Yes. But it would be MUCH simpler to use saved parameter queries.
>
> Bob Barrows
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.Serge Myrand Guest



Reply With Quote

