Data Table with Stored Procedure

Posted by Arun11 under ASP.NET on 7/4/2011 | Points: 10 | Views : 2447 | Status : [Member] | Replies : 1
Hi,

can anybody tell me how to covert Dataset to Datatable and then link DataTable to the stored procedure.

I dont want to write select query in the data Access layer. Instead i want to access stored procedure in DAL and populate selected tables in the grid.

Below is my Stored Procedure and code in Data access layer:

SP:

CREATE PROCEDURE [apqcstars].[SHR_Select_TemplateListByUser]
@USER_ID VARCHAR(40)
AS
BEGIN

SELECT
StudentHistoryTemplateID, TemplateName, CreatedBy, CreatedDate, ShowComment, IsPrivate, ClassSchedule, CustomGroupID, RosterID, PrintGroup, IsTemporary
FROM
StudentHistoryTemplate
WHERE
CreatedBy = @USER_ID

DAL:

public DataSet GetSHTemplateListByUserDA(string strUserID)
{
SqlCommand objSqlCommand = Execute.GetCommandObject();
objSqlCommand.CommandText = "SHR_Select_TemplateListByUser";
objSqlCommand.Parameters.AddWithValue("@USER_ID",strUserID);
objSqlCommand.CommandType = CommandType.StoredProcedure;
return Execute.ExecuteDataset(objSqlCommand);

I want to display only 3 columns of the table in the SP. How do i do that?

Thanks,
Arun




Responses

Posted by: Ndebata on: 7/4/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can access datatable from the Table Collection of DataTable something like
DataSet1.Tables[0]
will return you the first datatable in that dataset.

There are many ways you can show 3 columns in a grid view.
1.In the select list try to get only those three columns which you require to be displayed.
2.Or you can show only three columns in the gridview. (Hide rest of the columns in case you are automatically generating the columns else bind only these three columns)

Thanks,
Debata





Arun11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response