Syntax in asp page
am 15.01.2007 13:18:41 von Krij
Can anybody tell me about this:
conn.ConnectionString = "SELECT [Customernr], [Customername],
[OrderID], [Orderdate], [Itemname], [Ordersum], [Orderdiscount],
[Orderprice], [Orderamount] " + "\n" +
"WHERE Customernr = "' + <%txtCustnr.Text %> + '" FROM
[CustomerOrderHistory] ORDER BY [Orderdate]";
So what I try to obtain is getting a value from a textbox: txtCustnr.
The code is C# in an ASP 2.0 application
But this syntax drives me mad.
Any tip?
Re: Syntax in asp page
am 15.01.2007 14:24:00 von Mike Brind
"Krij" wrote in message
news:1168863521.253072.141440@38g2000cwa.googlegroups.com...
> Can anybody tell me about this:
>
> conn.ConnectionString = "SELECT [Customernr], [Customername],
> [OrderID], [Orderdate], [Itemname], [Ordersum], [Orderdiscount],
> [Orderprice], [Orderamount] " + "\n" +
> "WHERE Customernr = "' + <%txtCustnr.Text %> + '" FROM
> [CustomerOrderHistory] ORDER BY [Orderdate]";
>
> So what I try to obtain is getting a value from a textbox: txtCustnr.
>
> The code is C# in an ASP 2.0 application
>
> But this syntax drives me mad.
>
> Any tip?
You should try a dotnet group rather than this one, which deals with classic
asp. The busiest ones are microsoft.public.dotnet.framework.aspnet, or the
forums at www.asp.net. I suggest that future asp.net related questions are
posted there, because you will likely get a much quicker response.
However, the reason that the syntax is driving you mad is because you are
trying to assign a (badly formed) SQL statement to the ConnectionString
property. In fact, the SQL statement should be the CommandText.
There are a number of ways of approaching what you want to achieve. But, I
suggest that if you haven't already done so, you download a copy of
Microsoft Visual Web Developer, which is free, and use the wizards to
configure a DataSource, which will prompt you for the source of any
parameters that you want to feed into the query. In your case, the source
will be a control, txtCustomer. It will also help you to construct a SQL
statement properly.
--
Mike Brind
Re: Syntax in asp page
am 15.01.2007 19:10:57 von Brian Staff
> "WHERE Customernr = "' + <%txtCustnr.Text %> + '" FROM
Try re-coding this line to be:
"WHERE Customernr = '" + <% =txtCustnr.Text %> + "' FROM
Brian
Re: Syntax in asp page
am 15.01.2007 19:21:49 von exjxw.hannivoort
Brian Staff wrote on 15 jan 2007 in
microsoft.public.inetserver.asp.general:
>> "WHERE Customernr = "' + <%txtCustnr.Text %> + '" FROM
>
> Try re-coding this line to be:
>
> "WHERE Customernr = '" + <% =txtCustnr.Text %> + "' FROM
>
> Brian
A number being a number in the database, not a string,
and the SQL string being in the asp code part already,
and expecting ASP-VBS,
try:
sql = " ... WHERE Customernr = " & +txtCustnr.Text & " FROM ..."
or asp-Jscript:
sql = " ... WHERE Customernr = " + +txtCustnr.Text + " FROM ...";
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Syntax in asp page
am 15.01.2007 20:46:52 von Dave Anderson
Krij wrote:
> Can anybody tell me about this:
>
> conn.ConnectionString = "SELECT [Customernr], [Customername],
> [OrderID], [Orderdate], [Itemname], [Ordersum], [Orderdiscount],
> [Orderprice], [Orderamount] " + "\n" +
> "WHERE Customernr = "' + <%txtCustnr.Text %> + '" FROM
> [CustomerOrderHistory] ORDER BY [Orderdate]";
Yes. That is not a connection string.
http://msdn.microsoft.com/library/en-us/ado270/htm/mdproconn ectionstring.asp
Perhaps you want conn.Execute("SELECT ...")
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthcnne xecute.asp
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Re: Syntax in asp page
am 15.01.2007 21:15:31 von Brian Staff
Evertjan,
Yes, after re-reading my post, I declare it's completely wrong regarding server
and client code....so please dis-regard it.
I was focused on getting the quotes in the correct order and consequently did
not pay attention to the other details.
Sorry about that....Monday morning
Brian