Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to return columns like select

Author  Topic 

sayer
Starting Member

35 Posts

Posted - 2013-04-28 : 17:49:37
when create store procedure to use last code (Posted - 04/25/2013 : 03:30:39 )
and call Sp by c# reports no return columns like select statement

how to return columns ?

alter proc SP_Report_atend_lecture

as
begin
DECLARE @Pivot VARCHAR(4000) = '',
@sql VARCHAR(MAX) = '',
@PivotCols VARCHAR(MAX) ='COALESCE( '
SET @Pivot = STUFF( (SELECT ',[' + CAST( lesson_number AS VARCHAR) +']'
FROM View_1
GROUP BY lesson_number
FOR XML PATH('')), 1, 1 , '');

SET @PivotCols = @PivotCols + REPLACE( @Pivot, ',', ', ''0'' ), COALESCE( ') + ', ''0'')'

SET @sql = @sql + '
SELECT ID_student, ' + @PivotCols +
' FROM
( SELECT
lesson_number,
ID_student,
stae
FROM view_1
where stae=''no'' or stae=''yes''
) AS P
PIVOT
(
Max(stae) FOR lesson_number IN ( ' + @Pivot + ' )
) AS pv ';

EXEC (@sql)

end

please help me
to create report in c#

http://aman-services.net
for office
???? ???? ???????

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-28 : 18:14:16
It depends on how you are invoking the stored procedure from C#. What framework are you using to connect to SQL? If you are using ADO.Net you should use ExecuteReader or Fill ( of a data adapter) rather than ExecuteScalar or ExecuteNonquery.
Go to Top of Page

sayer
Starting Member

35 Posts

Posted - 2013-04-29 : 00:02:28
i use ADO.Net
fill data set but no column
i use wizard to create data set then create report then drop table and chose data-source
look at image
1- image chose data-source for report

2- test dataset

3- report no columns when call dataset

please help me


http://aman-services.net
for office
???? ???? ???????
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-29 : 00:45:59
thats because the sp uses a dynamic pivot and hence it cant determine metadat at designtime. I think better approach would be to put placeholders for all columns so that metadata will remain static and based on whether it has values or not you can write report expression for the same

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -