Syntax in asp page

K

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?
 
M

Mike Brind

Krij said:
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.
 
E

Evertjan.

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 ...";
 
D

Dave Anderson

Krij said:
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/mdproconnectionstring.asp

Perhaps you want conn.Execute("SELECT ...")
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthcnnexecute.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top