Fill Dataset by Data Adapter Using Stored Procedure ASP.Net

To fetch the data from database, we have to two options, one is to use the inline query or Stored procedures. We should prefer to use Stored procedure.

To get the dataset use the following method, we need to pass parameter if we need results based on conditions.

Must use the the namespaces :-
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;

Page Load Event and call the procedure
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGridView();
        }
    }

 private void BindGridView()
    {
        try
        {

            DataSet ds = new DataSet();
            SqlParameter[] objParameter = new SqlParameter[2];
            objParameter[0] = new SqlParameter("@HireDate", "2/14/2012");
            ds = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "ProjectExt_SP_CustomerListing", objParameter);
            if (ds != null)
            {
               if (ds.Tables[0].Rows.Count > 0)
                {
                    dlstCustomer.DataSource = ds.Tables[0];
                    dlstCustomer.DataBind();
                }
            }
            ds.Dispose();
        }
        catch (Exception ex)
        {
            //You can give Exception message here
        }
    }

 

Related Alrticles

FREE!!! Registration