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.