Monday, July 13, 2009

How to show a table data with mygeneration business object?

As from the last blog we came to learn about how to add a new entry in the table without any touch to the table. Lets consider the admin table. So we have got the following things already in hand:
1. _Admin.cs (Abstract class)
2. Admin.cs (Extension of _Admin)
3. Admin.sql (All doodad's stored procedures)

And it is expected we have already added some rows to the table. Now comes how we can show the value from the table. This is the most interesting part of mygeneration tool. You have 2 options
a. show values of one item
b. show values of all items in table

show values of one item:

This is quite easy. Here is the code following.
Suppose AdminID of Admin table is 5. So the following code shows Admin's info having AdminID=5.

try
{
Admin admin=new Admin();
admin.ConnectionString=ConfiguraionManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
/*Loaded the single instance*/

Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");

}

}
catch(Exception exc)
{}

show values for all items:

try
{
--------
same as previous
--------
if(admin.LoadByAll())
{
/*All instances loaded*/
admin.Rewind(); /*setting pointer to 0th row*/
do
{
Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");

}while(admin.MoveNext());


}
}
catch(Exception exc)
{}

So these are the way to access rows in the table. I think it is quite interesting, isn't it?

thanks.
Masud (14.7.9)



No comments:

Post a Comment