Wednesday, March 16, 2005

Insertion, Deletion, Updation Messages

Whenver we insert, delete, update any field in the database we usually tell the user that the operation is successfull. Most of us do it like this:

bool isInserted = myClass.InsertData(firstname,lastname);

if(isInserted)
{
prints inserted on the label
}
else
{
prints not inserted
}

Even though this is the common approach that is being used by most of the developers. One can easily save alot of coding by making a Messages class whose main purpose is to display messeges depending on the operation perform by the user.

DBMessages class can contain static methods like this:

public static string IsInserted(bool isInserted)
{
if(isInserted)
{
return "Data Inserted";
}
else
{
return "Data not inserted";
}
}

In the calling program you can access this easily by using a single line of code:

bool isInserted = MyClass.InsertData(firstname,lastname);
lblMessage.Text = DBMessages.Inserted(isInserted);

Using this approach saves alot of coding and you can easily modify the messages by just editing them on one place rather going to each module.




1 comment:

sista said...

hi it's sista, u replied my msg in asp.net forum regarding the textbox value in datalist.
I tried that and no error however i still can't get the value, dya have any idea why? http://forums.asp.net/878283/ShowPost.aspx
im so stucked.... X(