SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to return columns like select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sayer
Starting Member

Saudi Arabia
35 Posts

Posted - 04/28/2013 :  17:49:37  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3563 Posts

Posted - 04/28/2013 :  18:14:16  Show Profile  Reply with Quote
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

Saudi Arabia
35 Posts

Posted - 04/29/2013 :  00:02:28  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 04/29/2013 :  00:45:59  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000