Change the SqlDataSource

Is it possible to change the data that is selected by the SqlDataSource. I want to check if the data coming is within a certain range. If say it 0 or null or > 100 I want to alter the data value to a default value, say 1.
simshpAsked:
Who is Participating?
 
guru_samiCommented:
-->I assume then that one can not alter the values directly from the returned values of a sqldatasource select request

Is this for displaying purpose?

I guess you are trying to bind that datasource to some GridView or similar databound control...and you can handle one of their events to manipulate the DataItem for each row item.
0
 
SriVaddadiCommented:
You can handle the events provided by the SqlDataSource and override the behavior
0
 
SriVaddadiCommented:
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
simshpAuthor Commented:
thanks ... I have looked into this event, but don't know which parameter hook on to
0
 
HainKurtSr. System AnalystCommented:
change the SelectCommand

sqlDataSource.SelectCommand="SELECT * FROM myTable where isnull(col,0)=0 or col>100"
0
 
HainKurtSr. System AnalystCommented:
or use FilterExpression

sqlDataSource.FilterExpression="col > {0}"
sqlDataSource.FilterParameters(0).value = 100
0
 
SriVaddadiCommented:
0
 
simshpAuthor Commented:
I need more than filter or an alternative select ... the actual value return from the db needs to be altered. So if it returns a record with id = 0 ... I want to physically change it to say 1 ... not just remove it from the selection
0
 
guru_samiCommented:
You can use Case like below:

select id, Price =
Case
When Price =null then 1
when Price =null > 100 then 1
else Price
End
from tblPrice

http://msdn.microsoft.com/en-us/library/ms181765.aspx
0
 
simshpAuthor Commented:
Looks like  the easiest solution - I assume then that one can not alter the values directly from the returned values of a sqldatasource select request
0
 
simshpAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.