kamagra how much to take

Developing A Form WebPart – Part 5 – Wiring The Submission Event

The last portion required for the Form WebPart is getting the actual data into the database by wiring a submission event to the save button declared previously, easily accomplished by calling a stored procedure to accomplish the task. By pursing the option of using stored procedures, the option exists whether to use the native CLR stored procedures or to use a standard T-SQL stored procedures.

Since the submission of the data is relatively straightforward, the Forms WebPart uses three small classes to build extendable business logic. Using a base class allows the inclusion of code to enhance the Forms WebPart, such as allowing users management actions (editing or deleting entered information in the ID table, for instance). Accomplishing this is best performed by building out a concrete, abstract class to supply as the base class for the remaining database layer child, supplementary classes. An interface to facilitate this is not advisable since additional class versioning is much easier with abstract classes and virtual methods tend to provide a slight performance benefit in terms of performance execution. In the concrete IDRow_Base class, there are several actions that will be defined. The constructor will initialize a new instance of the IDRow_Base class, the ID property assessors will be set in order to get or set the ID column value, and using a System.Text.Stringbuilder there will be a string representation of the instance returned.

Here is the code for the abstract base class for the ID row table:

  1.         public abstract class IDRow_Base
  2.         {
  3.             private string _id;
  4.             public IDRow_Base()
  5.             {
  6.             }
  7.             public string ID
  8.             {
  9.                 get { return _id; }
  10.                 set { _id = value; }
  11.             }
  12.             public override string ToString()
  13.             {
  14.                 System.Text.StringBuilder dynStr = new System.Text.StringBuilder(GetType().Name);
  15.                 dynStr.Append(':');
  16.                 dynStr.Append("  ID=");
  17.                 dynStr.Append(ID);
  18.                 return dynStr.ToString();
  19.             }
  20.         }

Once you have defined the abstract class, it can be used to initialize a new instance of the IDrow base class, which is done by specifying the empty class constructor which inherits the IDRow_Base class. This allows the representation of an ID record object which is passed as a parameter to the actual insert method.

Here is the code for base class record representation:

  1.         public class IDRow : IDRow_Base
  2.         {
  3.             public IDRow()
  4.             {
  5.             }
  6.         }

There are several ways to accomplish the submission of the data into the backend database from the Form WebPart. One way to accomplish the insertion of the records would be to call a stored procedure by passing the stored procedure name into the CreateCommand method that takes either a string of T-SQL or a stored procedure name (this is shown in the following code). The easiest way is to just call a SQL script that contains the T-SQL insert method.

Here is the code for a record insert method by calling a stored procedure:

  1.         internal IDbCommand CreateCommand(string sqlText, bool procedure)
  2.         {
  3.             IDbCommand cmd = _connection.CreateCommand();
  4.             cmd.CommandText = sqlText;
  5.             cmd.Transaction = _transaction;
  6.             if (procedure)
  7.                 cmd.CommandType = CommandType.StoredProcedure;
  8.             return cmd;
  9.         }
  10.         public virtual void Insert(IDRow value)
  11.         {
  12.             IDbCommand cmd = _db.CreateCommand("dbo._ID_Insert", true);
  13.             AddParameter(cmd, "ID", value.ID);
  14.             cmd.ExecuteNonQuery();
  15.         }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>