Common Mistakes

Chapter 4 - Data Readers, Command Objects, and Web Server Controls
byJohn Kauffman, Fabio Claudio Ferracchiatiet al.?
Wrox Press ?2002

As in the previous chapter, We're going to conclude with a list of common pitfalls that you might encounter while experimenting with the examples presented in this chapter:

  • The web server control in your HTML page must have an ID that matches the object name you've used in the DataSource and DataBind() statements. It must also have the runat="server" attribute set.

  • Never instantiate a data reader object. We can let the command object's ExecuteReader() method do that job for us.

  • As always, know your data source. If you're getting an error, double check that you have the table and field names correct in your SQL query.

  • Your <asp:CheckBoxList> control must be in a <form> tag, and the <form> tag must also have the runat="server" attribute.

  • If you don't assign values to the DataValueField and DataTextField properties of the web server control, you won't get an error, but all the check boxes on your screen will be labeled System.Data.Common.DbDataRecord.

  • Note that the JET provider deletes spaces from column names, so Category ID will be displayed in the browser as CategoryID, without the space.

  • The DataValueField and DataTextValue properties must be set before the connection object's Close() method is called. Don't try to reduce the time your connection is open by setting these properties after the connection closes.

  • Similarly, the call to DataBind() must occur after DataValueField and DataTextField have been set.



Beginning ASP. NET 2.0 and Databases
Beginning ASP.NET 2.0 and Databases (Wrox Beginning Guides)
ISBN: 0471781347
EAN: 2147483647
Year: 2004
Pages: 263

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net