Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2003, 09:41 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default Help me with Dataview object.

I want to use the rowfilter method of the dataview object to show specific rows of a database that a person stated in a text box. The thing is is that if a person writes something that is not in the database, I want the an error message show that the record does not exist. Here is my code: -

if ((Request.Form["Author"] != null) && (Request.Form["Author"].Length > 0))
       {
         if(Author.Text == null)
         {
           Response.Write("This entry does not exist");
         }
         else
         {
           objDataView.RowFilter = "BookAuthor LIKE'" + Author.Text + "'";
         }
       }

Any ideas where I am going wrong??

Thanks

Adz - Portsmouth Massive
__________________
Adz - Learning The J2EE Ways.
 
Old November 20th, 2003, 12:32 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm not sure -- I've never bothered to use the Request.Form collection, because (as you have done in your code) you can access the page's controls directly.

Anyway, it looks like your code says "If the author is present, then if the author is not present then write an error message."

So it looks like a simple logic error to me. You can never write an error message with this code, because if the first condition is satisfied, the second condition will never be satisfied.


-Van
(Old dog learning new tricks...)
 
Old November 20th, 2003, 07:52 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to create the filter first:

objDataView.RowFilter = "BookAuthor LIKE '%" + Author.Text + "%'";

Note the addition of %s to assist the search.

Then, once the data is filtered, you need to see if there are any rows. It's illogical to say that rows don't exist because the user didn't enter anything.

Also, if this is all in ASPX, what is with all the Request and Response calls? ASP.Net is supposed to move code away from using that stuff. To provide feedback on the form you should use asp:label or literal controls and (en|dis)able then and set their text properties according to the appropriate outcomes.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid or Dataview cp75 Beginning PHP 2 September 26th, 2008 10:56 AM
dataview Yasho VB.NET 2002/2003 Basics 1 May 28th, 2007 03:40 AM
Help with DataReader/Dataview? saf ASP.NET 2.0 Basics 4 December 14th, 2006 01:01 PM
Ordering a dataview Louisa VB.NET 2002/2003 Basics 1 November 11th, 2004 10:04 AM
DataView vivi C# 4 November 10th, 2003 01:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.