whats recommended way to handle this? no records

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

I currently have an asp.net detail page that is populated with data from a
sql 2000 table. Currently the user gets to this page by clicking on an ID
link from a different page so I know that ID does in fact exist. However I
am now adding a way for the user to enter in an ID into a textbox manually
and click a button to go directly to a particular ID. So now I need to
account for the user entering an ID that does not exist.

what is the recomended way to handle this common scenario in .net?

1) run the query and check a record count? then redirect to an error page
for the 'no records found' message?
2) let the functions on the page that are expecting the record fail and trap
the error, followed by redirecting to an error message page?

any info is appreciated. Thanks
 
It depends on the application. Realistically, unless you have a start/finish
integer that you can load into Client Side JavaScript, you will have to take
a trip to the database. The question here is whether or not you are caching
the data on the server or hitting the database each time.

Either way, the method is fairly similar on the server side.

If the database, you will query using the ID and return the value. If
nothing, however, you will have to reconstruct the original set, so this is
not extremely efficient.

If you cache the data (most likely in a DataSet), you can use a filter on a
view and see if anything remains. if not, it is a bogus ID and you can rebind
the DataSet to the page without another trip to the database.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
thanks for the reply.

Cowboy (Gregory A. Beamer) - MVP said:
It depends on the application. Realistically, unless you have a start/finish
integer that you can load into Client Side JavaScript, you will have to take
a trip to the database. The question here is whether or not you are caching
the data on the server or hitting the database each time.

Either way, the method is fairly similar on the server side.

If the database, you will query using the ID and return the value. If
nothing, however, you will have to reconstruct the original set, so this is
not extremely efficient.

If you cache the data (most likely in a DataSet), you can use a filter on a
view and see if anything remains. if not, it is a bogus ID and you can rebind
the DataSet to the page without another trip to the database.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top