Another parameter question

  • Thread starter Thread starter RICK
  • Start date Start date
R

RICK

Must be doing something wrong here as my query is coming up with no records.
Please help

dbconn.Open()
sql="SELECT * FROM WebQry_NCList_FamilyList where Family = '@family'"
DBSQLCOMMAND.Parameters.Add("@family","Smith")
dbcomm=New OleDbCommand(sql,dbconn)
 
Rick,

You have to do something with that dbcomm or either use a OleDbAdapter.

However with only this code there will not come up any record

Cor
 
Here is the full code. Will this code help in trying to decipher my issue?

_______________

<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Text"%>

<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" &
server.mappath("/databases/cpcweb.mdb"))
Dim DBSQLCOMMAND As SqlClient.SqlCommand

DBSQLCOMMAND = New SqlClient.SqlCommand
DBSQLCOMMAND.Parameters.Add("@family","Smith")

dbconn.Open()



SQL="SELECT * FROM WebQry_FamilyList where Family='@family'"

dbcomm=New OleDbCommand(sql,dbconn)

dbread=dbcomm.ExecuteReader()
family.DataSource=dbread
family.DataBind()
dbread.Close()
dbconn.Close()
end sub


</script>

<html>
<body>

<form runat="server">
<asp:DataList
id="family"
runat="server"
cellpadding="2"
cellspacing="2"
borderstyle="inset"
backcolor="#e8e8e8"
width="50%"
headerstyle-font-name="Verdana"
headerstyle-font-size="12pt"
headerstyle-horizontalalign="center"
headerstyle-font-bold="True"
itemstyle-backcolor="#778899"
itemstyle-forecolor="#ffffff"
footerstyle-font-size="9pt"
footerstyle-font-italic="True">

<HeaderTemplate>
Family Table
</HeaderTemplate>

<ItemTemplate><%#Container.DataItem("family")%></ItemTemplate>

<FooterTemplate>
Source: The Database
</FooterTemplate>

</asp:DataList>
</form>

</body>
</html>
 
The parameter placeholder includes handling the appropriate delimiters.
You shouldn't include them...
I missed that one.
BTW I'm not even sure it will work. AFAIK Access doesn't support named
parameters.

No but you can use @Family, however it is nothing more then ?.
Like you wrote being the unnamed placeholder that are distinguished by their
positions
and not by their names
 
OK, so what I am really after here in the very end is to somehow get my query
to read
sql="SELECT * FROM WebQry_NCList_FamilyList where Family = strfamily

where strfamily is some variable that comes from a form on the previous
page. Can that be done? And if so, how?
 
Well, kind of answered my question:

Dim strFamily
strFamily = "Acanthaceae"

SQL="SELECT * FROM WebQry_NCList_FamilyList where Family= '" + strFamily + "'"

Now, how can I make this more secure?
 
Again, I think my question may have been answered. In classic I have been
using

set rs=server.createobject("adodb.recordset")
conn.MyProcedure parmval1,...,parmvalN, rs

Was wondering if something similar could be used in .net.

A post from Barrows follows:

"You can also use this technique if your procedure returns a
recordset:
set rs=server.createobject("adodb.recordset")
'optionally, set the cursor location and type properties
conn.MyProcedure parmval1,...,parmvalN, rs

This technique does not work in ADO.Net, so if you are considering
porting to dotnet, then you should avoid this technique."

If someone can verify for me that this is still the case I will stop trying
to port my stuff over to .net.
 
Rick,

There is probably really nobody here who cares about it of you go to Net of
not.

There have been as well a lot of people who did not want to go to disc,
they stayed with the punch card.

This kind of behaviour is solved automatically.

Cor
 
Back
Top