All we have to do to get an initialized StudentDataAccess object is pass a valid studentId value. What I mean by valid in this context is that the value you pass to the constructor matches one of the values of the StudentID column of the Students table. To see this in action write the following code in the Page_Load() event handler.
Try to pass to the second object's constructor a value that doesn't exist in the database table, like 100, and see what would happen.
As you can see the object has not been initialized from the database and the studentId field has the value -1.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |