Home > Archive > ASP > January 2007 > Syntax in asp page
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Syntax in asp page
|
|
|
| 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?
| |
| Mike Brind 2007-01-15, 6:56 pm |
|
"Krij" <gsb58@start.no> 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
| |
| Brian Staff 2007-01-15, 6:56 pm |
| > "WHERE Customernr = "' + <%txtCustnr.Text %> + '" FROM
Try re-coding this line to be:
"WHERE Customernr = '" + <% =txtCustnr.Text %> + "' FROM
Brian
| |
| Evertjan. 2007-01-15, 6:56 pm |
| Brian Staff wrote on 15 jan 2007 in
microsoft.public.inetserver.asp.general:
>
> 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)
| |
| Dave Anderson 2007-01-15, 6:56 pm |
| 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/e...ctionstring.asp
Perhaps you want conn.Execute("SELECT ...")
http://msdn.microsoft.com/library/e...hcnnexecute.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.
| |
| Brian Staff 2007-01-15, 6:56 pm |
| 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<g>
Brian
|
|
|
|
|