PC Review


Reply
Thread Tools Rate Thread

ASP.NET Query application made simple?

 
 
Steven Blair
Guest
Posts: n/a
 
      25th Dec 2006
Query application made simple?

I have to use ASP.NET quite often to knock up quick protype
applications.
Generally, these applications have some components for querying and an
area of screen for displaying the results.

Using GridViews and SqlDataSource, I can almost make the application
with no code. My where clause is handled by the SqlDataSource.
What I would like to know is, can the SqlDataSource be made to be
"intelligent".
Following example shows what I need:

I add a SqlDataSource and DetailsView.
Add a TextBox and Button.
The Textbox value is added as a parameter to the SqlDataSource.

So, the program is run and I type in a value and hit the button, and it
brings me back the data.
But, how could I make the SqlDataSource "know" that the value might not
be used soemtimes.
If the Textbox is empty, I would want all the rows returned (not in a
DetailsView, but just in general)

If I leave the value empty, the select statement would look soemthing
like:

select * from myTable where colName =

The only way I can think of doing this is messy string manipulation.
What I want is a re-usbale approach.

Anyone got any ideas / techniques for this problem?

Steven



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      25th Dec 2006
"Steven Blair" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> select * from myTable where colName =
>
> The only way I can think of doing this is messy string manipulation.
> What I want is a re-usbale approach.
>
> Anyone got any ideas / techniques for this problem?


Firstly, if your app is on the public Internet, don't do this!!!

What would happen if someone typed the following into your TextBox:?

'x'; DROP TABLE myTable;--

http://www.google.co.uk/search?hl=en...2+DELETE&meta=


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      25th Dec 2006
This is probably neither a C# specific question or an ASP.NET question and
probably should have been directed to the SQL or ASP.NET Group, but here you
go:

select * from MYTABLE WHERE 1=1
AND 1 =
CASE WHEN @query IS NOT NULL AND COLUMNNAME=@query THEN 1
WHEN @query IS NULL THEN 1 END

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Steven Blair" wrote:

> Query application made simple?
>
> I have to use ASP.NET quite often to knock up quick protype
> applications.
> Generally, these applications have some components for querying and an
> area of screen for displaying the results.
>
> Using GridViews and SqlDataSource, I can almost make the application
> with no code. My where clause is handled by the SqlDataSource.
> What I would like to know is, can the SqlDataSource be made to be
> "intelligent".
> Following example shows what I need:
>
> I add a SqlDataSource and DetailsView.
> Add a TextBox and Button.
> The Textbox value is added as a parameter to the SqlDataSource.
>
> So, the program is run and I type in a value and hit the button, and it
> brings me back the data.
> But, how could I make the SqlDataSource "know" that the value might not
> be used soemtimes.
> If the Textbox is empty, I would want all the rows returned (not in a
> DetailsView, but just in general)
>
> If I leave the value empty, the select statement would look soemthing
> like:
>
> select * from myTable where colName =
>
> The only way I can think of doing this is messy string manipulation.
> What I want is a re-usbale approach.
>
> Anyone got any ideas / techniques for this problem?
>
> Steven
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
 
Steven Blair
Guest
Posts: n/a
 
      26th Dec 2006
It's for local intranet use only.

Hmm, I hadn't even thought bout tailoring the SQL to do the job. I was
focused on thinking biout doing something fancy in the C# components.
But looking at the code, I think you may have made my life that little
bit easier



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Video collection made simple danstocker Freeware 0 24th Sep 2011 06:03 PM
Simple function made difficult GreenMonster Microsoft Excel Programming 2 15th Jun 2005 04:11 PM
File Management Made SIMPLE? Admiral Halsey Windows XP Help 10 23rd Jan 2005 03:59 AM
Load balancing made simple? GeekBoy Microsoft ASP .NET 10 25th Oct 2004 08:25 PM
A simple home-made StringGrid Tal Sharfi Microsoft C# .NET 0 19th Aug 2004 09:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:32 PM.