473,403 Members | 2,338 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,403 software developers and data experts.

SqlDataSource WHERE clause

I'm sure this will be a simple one...

I have a SqlDataSource that I need a WHERE
clause on it ONLY when the querystring contains
"ProjectID", otherwise I don't need it.

If you come to the page with: .aspx?ProjectID=1039
the DataView will only populate with 1039 projects,
otherwise, you get all project records.

Here's the way I have it now.

<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="ProjectID"
QueryStringField="ProjectID" Type="Int32" />
</SelectParameters>

What can I do to get all records when there's no querystring?

Thanks!

Steven
Nov 7 '07 #1
3 2518
Your default value is "0" check for that value then in your SQL or Stored
Procedure do something like this:
IF @ProjectID = 0
BEGIN
Select * from...
END
ELSE
BEGIN
Select * from table where ProjectId = @ProjectID
END

Regards,
Brian K. Williams

"Steven Edison" <Ed*******@newsgroups.nospamwrote in message
news:7B**********************************@microsof t.com...
I'm sure this will be a simple one...

I have a SqlDataSource that I need a WHERE
clause on it ONLY when the querystring contains
"ProjectID", otherwise I don't need it.

If you come to the page with: .aspx?ProjectID=1039
the DataView will only populate with 1039 projects,
otherwise, you get all project records.

Here's the way I have it now.

<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="ProjectID"
QueryStringField="ProjectID" Type="Int32" />
</SelectParameters>

What can I do to get all records when there's no querystring?

Thanks!

Steven

Nov 7 '07 #2
Thanks Brian,

It's not a stored procedure.
I was changing my sql in PageLoad if the QueryString["ProjectID"]
was null, but I thought there must be a better way. That's why
I came online looking for suggestions.

Steven

"Brian Williams" <wi*******@issuecontrol.comwrote in message
news:#1**************@TK2MSFTNGP06.phx.gbl...
Your default value is "0" check for that value then in your SQL or Stored
Procedure do something like this:
IF @ProjectID = 0
BEGIN
Select * from...
END
ELSE
BEGIN
Select * from table where ProjectId = @ProjectID
END

Regards,
Brian K. Williams

"Steven Edison" <Ed*******@newsgroups.nospamwrote in message
news:7B**********************************@microsof t.com...
>I'm sure this will be a simple one...

I have a SqlDataSource that I need a WHERE
clause on it ONLY when the querystring contains
"ProjectID", otherwise I don't need it.

If you come to the page with: .aspx?ProjectID=1039
the DataView will only populate with 1039 projects,
otherwise, you get all project records.

Here's the way I have it now.

<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="ProjectID"
QueryStringField="ProjectID" Type="Int32" />
</SelectParameters>

What can I do to get all records when there's no querystring?

Thanks!

Steven

Nov 7 '07 #3
LVP
Can this only be done in a Stored procedure.
Why can't be done in code behind???
"Brian Williams" <wi*******@issuecontrol.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Your default value is "0" check for that value then in your SQL or Stored
Procedure do something like this:
IF @ProjectID = 0
BEGIN
Select * from...
END
ELSE
BEGIN
Select * from table where ProjectId = @ProjectID
END

Regards,
Brian K. Williams

"Steven Edison" <Ed*******@newsgroups.nospamwrote in message
news:7B**********************************@microsof t.com...
>I'm sure this will be a simple one...

I have a SqlDataSource that I need a WHERE
clause on it ONLY when the querystring contains
"ProjectID", otherwise I don't need it.

If you come to the page with: .aspx?ProjectID=1039
the DataView will only populate with 1039 projects,
otherwise, you get all project records.

Here's the way I have it now.

<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="ProjectID"
QueryStringField="ProjectID" Type="Int32" />
</SelectParameters>

What can I do to get all records when there's no querystring?

Thanks!

Steven


Nov 7 '07 #4

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

Similar topics

1
by: Henry Habermacher [MVP Access] | last post by:
Environment: VS2005, ASP.Net 2.0, SQLServer 2000, VB.Net, IIS6 I use a GridView Control which is based on a SQLDataSource. The datasource is based on a Select statement and is filtered by the...
2
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
4
by: Dabbler | last post by:
I need to convert a CompanyId in one table to Company Name from another table for an ItemTemplate. I thought I would just add another SqlDataSource but not sure how to eval with the CompanyId...
9
by: Dan Sikorsky | last post by:
When I hit the Test Query button in the SqlDataSource design, all the rows come back. But when I run the website, without any changes, in the IDE, the GridView tied to the SqlDataSoure is empty. ...
0
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
1
by: jobs | last post by:
Cannot find column . Am I missing something here... SelectCommand="SELECT , , , refid FROM " FilterExpression="phone_nbr like @phone_nbr + '%'"
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
0
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm using a gridview with a sqldatasource and i know how to specify a control for the where clause that limits records returned from database. But what do you do when you want the added...
2
by: Cirene | last post by:
I have a gridview that is filtered by a databound dropdownlist. I've set AppendDataBound to True and added the item "ALL" in the dropdownlist. My gridview is supposed to be filtered by this...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.