SqlDataSource WHERE clause

S

Steven Edison

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
 
B

Brian Williams

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
 
S

Steven Edison

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
 

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,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top