//The stored procedure is as follows
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetAccountCode]
@CompCode int,
@AccountTypeID int
As
select AccountCode as Col_01,AccountName as Col_02,left(AccountName,20) as Col_03,AccountTypeID as Col_04,AccountStatusID as Col_05
from RefAccount
where CompCode = @CompCode and AccountTypeID = @AccountTypeID
order by AccountTypeID,AccountCode
//This is the option 1 that uses stored procedure command Type:
SqlCommand cmd = new SqlCommand("GetAccountCode", cnDBAAA);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CompCode", CompCode);
cmd.Parameters.AddWithValue("@AccountTypeID", AccountTypeID);
try
{
cnDBAAA.Open();
//Set datasource and bind table data to gridview.
dgSelection.DataSource = cmd.ExecuteReader();
dgSelection.DataBind();
//Clear datasource ready for use in next gridview data
cmd.Connection.Close();
cmd.Connection.Dispose();
}
catch (Exception)
{
}
finally
{
cnDBAAA.Close();
}
//This is option 2 which in which i use a sql adapter with fill method to populate grid view data.
SQLString = "EXEC GetAccountCode " + CompCode + "," + AccountTypeID;
try
{
SqlDataAdapter sdaDBAAA = new SqlDataAdapter(SQLString, cnDBAAA);
cnDBAAA.Open();
sdaDBAAA.Fill(dsCodes);
//Set datasource and bind table data to gridview.
dgSelection.DataSource = dsCodes;
dgSelection.DataBind();
//Clear datasource ready for use in next gridview data
dsCodes.Clear();
}
catch (Exception)
{
}
finally
{
cnDBAAA.Close();
}
//The skin id for the Grid
|