using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

using Utilities;

using System.Data;

using System.Data.SqlClient;

 

namespace Database

{

    public partial class StoredProcedureExample1 : System.Web.UI.Page

    {

        DBConnect objDB = new DBConnect();

        SqlCommand objCommand = new SqlCommand();

        string strSQL;

 

        protected void Page_Load(object sender, EventArgs e)

        {

 

        }

 

        protected void btnDisplayAccounts_Click(object sender, EventArgs e)

        {

            // Set the SQLCommand object's properties for executing a Stored Procedure

            objCommand.CommandType = CommandType.StoredProcedure;

            objCommand.CommandText = "GetAccounts";     // identify the name of the stored procedure to execute

 

            // Execute the stored procedure using the DBConnect object and the SQLCommand object

            DataSet myDS = objDB.GetDataSetUsingCmdObj(objCommand);

 

            gvCustomers.DataSource = myDS;

            gvCustomers.DataBind();

        }

 

        protected void btnFindAccount_Click(object sender, EventArgs e)

        {

            // Set the SQLCommand object's properties for executing a Stored Procedure

            objCommand.CommandType = CommandType.StoredProcedure;

            objCommand.CommandText = "GetAccountById";     // identify the name of the stored procedure to execute

 

            // Pass an input parameter value to the stored procedure that is used for the @theID built-in parameter

            // objCommand.Parameters.AddWithValue("@theID", int.Parse(txtName.Text));

            SqlParameter inputParameter = new SqlParameter("@theID", int.Parse(txtName.Text));

            inputParameter.Direction = ParameterDirection.Input;

            inputParameter.SqlDbType = SqlDbType.Int;

            inputParameter.Size = 4;                                // 4-bytes

            objCommand.Parameters.Add(inputParameter);

 

            // Execute the stored procedure using the DBConnect object and the SQLCommand object

            DataSet myDS = objDB.GetDataSetUsingCmdObj(objCommand);

 

            gvCustomers.DataSource = myDS;

            gvCustomers.DataBind();

        }

 

        protected void btnFindAccountsByName_Click(object sender, EventArgs e)

        {

            // Set the SQLCommand object's properties for executing a Stored Procedure

            objCommand.CommandType = CommandType.StoredProcedure;

            objCommand.CommandText = "GetAccountByName";     // identify the name of the stored procedure to execute

 

            // Pass an input parameter value to the stored procedure that is used for the @theName built-in parameter

            // objCommand.Parameters.AddWithValue("@theName", txtName.Text);

            SqlParameter inputParameter = new SqlParameter("@theName", txtName.Text);

            inputParameter.Direction = ParameterDirection.Input;

            inputParameter.SqlDbType = SqlDbType.VarChar;

            inputParameter.Size = 50;                                // 50-bytes ~ varchar(50)

            objCommand.Parameters.Add(inputParameter);

 

            // Execute the stored procedure using the DBConnect object and the SQLCommand object

            DataSet myDS = objDB.GetDataSetUsingCmdObj(objCommand);

 

            gvCustomers.DataSource = myDS;

            gvCustomers.DataBind();

        }

    }

}