472,111 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

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?

Jan 15 '07 #1
5 1134

"Krij" <gs***@start.nowrote in message
news:11**********************@38g2000cwa.googlegro ups.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
Jan 15 '07 #2
"WHERE Customernr = "' + <%txtCustnr.Text %+ '" FROM

Try re-coding this line to be:

"WHERE Customernr = '" + <% =txtCustnr.Text %+ "' FROM

Brian
Jan 15 '07 #3
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)
Jan 15 '07 #4
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...tionstring.asp

Perhaps you want conn.Execute("SELECT ...")
http://msdn.microsoft.com/library/en...cnnexecute.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.
Jan 15 '07 #5
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

Jan 15 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Xah Lee | last post: by
4 posts views Thread by Toonman | last post: by
reply views Thread by Mark Phanides | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.