The problem that the stored procedure does not directly return the result set

Source: Internet
Author: User

Suppose there is a stored procedure like this:

Set Quoted_identifier On  
Go
Set Ansi_nulls Off  
Go
If   Exists ( Select   *   From DBO. sysobjects Where ID =   Object_id (N ' [DBO]. [findthestudents] ' ) And   Objectproperty (ID, n ' Isprocedure ' ) =   1 )
Drop   Procedure   [ DBO ] . [ Findthestudents ]
Go


/**/ /*Queries the stored procedures of students with the specified sequence number and admission time.*/
Create   Procedure Findthestudents
(
@ Idlist   Varchar ( 1000 ),
@ Begintime   Varchar ( 20 ),
@ Endtime   Varchar ( 20 )
)
As
Begin
Declare   @ S   Varchar ( 4000 )
Set   @ S = ' Select ID as "no.", name as "name", Tel as "phone" from student where classid in ( ' + @ Idlist + ' ) And logtime" ' + @ Begintime + ' "And" ' + @ Endtime + ' " '
Exec ( @ S )
End
Go
Set Quoted_identifier Off  
Go
Set Ansi_nulls On  
Go

Now you need to add a query in the dataset adapter of the Dal layer to execute the stored procedure and return the corresponding result set. Based on past experience, if the stored procedure is simply executed Select ID, name, tel From Student Where Classid In ( 1 , 2 , 3 ) And Logtime Between   ' 2005-1-1 '   And   ' 2006-1-1 '  

Such a statement will certainly generate a corresponding result set table during the Query Process of the stored procedure.

however, if the preceding stored procedure is used, a query statement @ s is constructed first, and then exec (@ s) is called ), vs2005 does not automatically construct a table in the result set.
in this case, you have two options: manually edit the table, and leave the table empty;
for the first case:
to manually edit the table, you must be able to predict the structure of the table in advance and use the query later, the header name of the returned result set is displayed as defined here.
for the second case:
If the table is left empty, when this table is used in the future, the table content will be automatically filled according to the content returned by the stored procedure. If this result set is associated with a gridview, all the content in the table will be displayed normally; however, this method also has its disadvantage, that it cannot know the row type of the table during compilation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.