473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Dynamic SQL handling, and edit-grids?

I am generally new to dot.net, coming from "scriptish" web languages
such as ColdFusion and Php.

I have a few questions if you don't mind.

First, how does one go about inserting dynamic SQL during run-time
without lots of quotes? For example, adding "AND" clauses that may or
may not be present based on the query criteria form.

Some of the asp.net examples use the one-line append approach which
seems awkward to work with (see 2nd example below).

For example, in ColdFusion one can do something like:

<CFquery settings="foo"> // query block - approx syntax only
SELECT *
FROM myTable
WHERE 1=1 #andClause# // insert variable string
<CFif x equals 1> // IF statement
ORDER BY zip, zap
<CFelse>
ORDER BY norg
</CFif> // end-if
</CFquery> // end-query

Here "andClause" is an "embedded" variable that is inserted into the
SQL string at run-time. It may contain something like "and x = y and k
= 2". It can also be blank (which is why the query has "1=1"). This is
important because the parameters cannot be hard-wired ahead of time
unlike what some template-based SQL preprocessors use. A sample
"SqlDataSource" ASPX tag I looked into had this problem. It assumed all
the "slots" will always have a usable value. Optional
parameters/clauses is a common need for non-trivial forms and reports.

I remember the old-style ASP required something like:

sql = "SELECT * "
sql = sql & "FROM myTable "
sql = sql & "WHERE 1=1 " & andClause
if x = 1 then
sql = sql & " ORDER BY zip, zap "
else
sql = sql & " ORDER BY norg "
end if
rs = db.execute(sql) ...

The quoting and string appending can get annoying and error-prone for
longer SQL, especially if one has to copy and paste back and forth to
test the SQL in a query processor (such as Toad or SQL-Server edit
window).

I am wondering what techniques one uses to simplify dynamic SQL
handling in asp.net.

Second, does asp.net have a decent editable grid? This would be a
spreadsheet-like grid interface that can accept new data. ColdFusion
has CFgrid for this. It is a bit clunky and crashy, but good enough for
internal or small stuff.

I have seen a lot of half-@ss implementations that don't measure up to
what a user expects from client-server or desktop type apps
(spreadsheets, MS-Access, VB6, etc.). For example, some web grid
widgets don't have scroll-bars but Prev/Next buttons instead; others
don't recognize the Down-Arrow key to move between rows; others have
the column title row disappear when you scroll down; and many just
crash a lot. Apparently it is a tough problem to solve given how few
solutions there are. There are some JavaScript solutions that cost
bucks.

Thanks in advance for your response.

-T-

May 1 '06 #1
3 1713
Topmind,

I prefer to use stored procedures myself, but the answer to your question is
that Sql Commands are easy to form in asp.net and have built in parameter
checking. You can now specify a parameter right in the string and then add
the parameter to the sql command and the parameter will be checked and then
inserted into the string:

using System.Data;
using System.Data.SqlClient;

using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet userDataset = new DataSet();
SqlDataAdapter myDataAdapter = new SqlDataAdapter(
"SELECT au_lname, au_fname FROM Authors WHERE au_id = @au_id",
connection);
myCommand.SelectCommand.Parameters.Add("@au_id", SqlDbType.VarChar, 11);
myCommand.SelectCommand.Parameters["@au_id"].Value = SSN.Text;
myDataAdapter.Fill(userDataset);
}

The answer to your second question is that you can use a datagrid in asp.net
1.1 or a gridview in asp.net 2.0.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"topmind" <to*****@technologist.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
I am generally new to dot.net, coming from "scriptish" web languages
such as ColdFusion and Php.

I have a few questions if you don't mind.

First, how does one go about inserting dynamic SQL during run-time
without lots of quotes? For example, adding "AND" clauses that may or
may not be present based on the query criteria form.

Some of the asp.net examples use the one-line append approach which
seems awkward to work with (see 2nd example below).

For example, in ColdFusion one can do something like:

<CFquery settings="foo"> // query block - approx syntax only
SELECT *
FROM myTable
WHERE 1=1 #andClause# // insert variable string
<CFif x equals 1> // IF statement
ORDER BY zip, zap
<CFelse>
ORDER BY norg
</CFif> // end-if
</CFquery> // end-query

Here "andClause" is an "embedded" variable that is inserted into the
SQL string at run-time. It may contain something like "and x = y and k
= 2". It can also be blank (which is why the query has "1=1"). This is
important because the parameters cannot be hard-wired ahead of time
unlike what some template-based SQL preprocessors use. A sample
"SqlDataSource" ASPX tag I looked into had this problem. It assumed all
the "slots" will always have a usable value. Optional
parameters/clauses is a common need for non-trivial forms and reports.

I remember the old-style ASP required something like:

sql = "SELECT * "
sql = sql & "FROM myTable "
sql = sql & "WHERE 1=1 " & andClause
if x = 1 then
sql = sql & " ORDER BY zip, zap "
else
sql = sql & " ORDER BY norg "
end if
rs = db.execute(sql) ...

The quoting and string appending can get annoying and error-prone for
longer SQL, especially if one has to copy and paste back and forth to
test the SQL in a query processor (such as Toad or SQL-Server edit
window).

I am wondering what techniques one uses to simplify dynamic SQL
handling in asp.net.

Second, does asp.net have a decent editable grid? This would be a
spreadsheet-like grid interface that can accept new data. ColdFusion
has CFgrid for this. It is a bit clunky and crashy, but good enough for
internal or small stuff.

I have seen a lot of half-@ss implementations that don't measure up to
what a user expects from client-server or desktop type apps
(spreadsheets, MS-Access, VB6, etc.). For example, some web grid
widgets don't have scroll-bars but Prev/Next buttons instead; others
don't recognize the Down-Arrow key to move between rows; others have
the column title row disappear when you scroll down; and many just
crash a lot. Apparently it is a tough problem to solve given how few
solutions there are. There are some JavaScript solutions that cost
bucks.

Thanks in advance for your response.

-T-

May 2 '06 #2
Just out of curiosity, are you the topmind of TableOrientedProgramming
fame, or am I accusing an innocent man of RelationalWeenieship?

May 2 '06 #3

S. Justin Gengo wrote:
Topmind,

I prefer to use stored procedures myself,
As a side note, Stored Procedures tend to slow development and
maintenence because you have to make many changes in two places instead
of just one. That will cost tens of thousands of dollars over the long
run. They do have their advantages, but there are tradeoffs.
but the answer to your question is
that Sql Commands are easy to form in asp.net and have built in parameter
checking. You can now specify a parameter right in the string and then add
the parameter to the sql command and the parameter will be checked and then
inserted into the string:

using System.Data;
using System.Data.SqlClient;

using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet userDataset = new DataSet();
SqlDataAdapter myDataAdapter = new SqlDataAdapter(
"SELECT au_lname, au_fname FROM Authors WHERE au_id = @au_id",
connection);
myCommand.SelectCommand.Parameters.Add("@au_id", SqlDbType.VarChar, 11);
myCommand.SelectCommand.Parameters["@au_id"].Value = SSN.Text;
myDataAdapter.Fill(userDataset);
}

Okay, but this does not seem to address the *optional* parameters
and/or clauses that I was concerned about.


The answer to your second question is that you can use a datagrid in asp.net
1.1 or a gridview in asp.net 2.0.

But the only asp.net examples I have seen suffer from one or more of
the grid problems listed.


Regards,

--
S. Justin Gengo
Web Developer / Programmer
Thanks for your feedback.

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"topmind" <to*****@technologist.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
I am generally new to dot.net, coming from "scriptish" web languages
such as ColdFusion and Php.

I have a few questions if you don't mind.

First, how does one go about inserting dynamic SQL during run-time
without lots of quotes? For example, adding "AND" clauses that may or
may not be present based on the query criteria form.

Some of the asp.net examples use the one-line append approach which
seems awkward to work with (see 2nd example below).

For example, in ColdFusion one can do something like:

<CFquery settings="foo"> // query block - approx syntax only
SELECT *
FROM myTable
WHERE 1=1 #andClause# // insert variable string
<CFif x equals 1> // IF statement
ORDER BY zip, zap
<CFelse>
ORDER BY norg
</CFif> // end-if
</CFquery> // end-query

Here "andClause" is an "embedded" variable that is inserted into the
SQL string at run-time. It may contain something like "and x = y and k
= 2". It can also be blank (which is why the query has "1=1"). This is
important because the parameters cannot be hard-wired ahead of time
unlike what some template-based SQL preprocessors use. A sample
"SqlDataSource" ASPX tag I looked into had this problem. It assumed all
the "slots" will always have a usable value. Optional
parameters/clauses is a common need for non-trivial forms and reports.

I remember the old-style ASP required something like:

sql = "SELECT * "
sql = sql & "FROM myTable "
sql = sql & "WHERE 1=1 " & andClause
if x = 1 then
sql = sql & " ORDER BY zip, zap "
else
sql = sql & " ORDER BY norg "
end if
rs = db.execute(sql) ...

The quoting and string appending can get annoying and error-prone for
longer SQL, especially if one has to copy and paste back and forth to
test the SQL in a query processor (such as Toad or SQL-Server edit
window).

I am wondering what techniques one uses to simplify dynamic SQL
handling in asp.net.

Second, does asp.net have a decent editable grid? This would be a
spreadsheet-like grid interface that can accept new data. ColdFusion
has CFgrid for this. It is a bit clunky and crashy, but good enough for
internal or small stuff.

I have seen a lot of half-@ss implementations that don't measure up to
what a user expects from client-server or desktop type apps
(spreadsheets, MS-Access, VB6, etc.). For example, some web grid
widgets don't have scroll-bars but Prev/Next buttons instead; others
don't recognize the Down-Arrow key to move between rows; others have
the column title row disappear when you scroll down; and many just
crash a lot. Apparently it is a tough problem to solve given how few
solutions there are. There are some JavaScript solutions that cost
bucks.

Thanks in advance for your response.

-T-


May 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JP011 | last post by:
Hello I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the...
6
by: Mark | last post by:
I have been working for quite some time on this issue which in theory should be quite simple. The problem is that the Cancel and Save events are not fired when their respective buttons are...
0
by: Martin | last post by:
Hi. I had a very frustrating afternoon and evening but I have got it all under control now so all of a sudden I am in a good mood. I want to share some insights on output caching with you lot. ...
0
by: Colin Ramsay | last post by:
Hi all, I don't normally post swathes of code like this but I am truly banging my head off my desk here... I've dynamically created a datagrid within a usercontrol. There are two columns...
2
by: John Ninan | last post by:
I am creating Dynamic Usercontrol in Asp.net application. In this application I have a combobox(aspx Page). Which contains various items. Based on item selected I am dynamically populating...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
0
by: Achim Domma (SyynX Solutions GmbH) | last post by:
Hi, in a repeater control I can create a postback link like this: <a href=<%# DataBinder.Eval(Container.DataItem, "EditLink") %>></a> The EditLink property of the data item uses...
5
by: mk | last post by:
Hi all, The requirement is like this.. I have to update the table with the parameters from front end like at some times i need to update one parameters and some times i have to update more...
8
by: BD | last post by:
How can I duplicate the behavior of the operating system shortcut keys in my application? For example, my windows form has 5 controls (textboxes), the operating system will pickup which control...
2
Frinavale
by: Frinavale | last post by:
I've created a ASP.NET control that displays a "book" of schedules. It dynamically displays scheduling times and allows the user to page through the schedules. It also lets the user edit the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.