return table name with query results from stored procedure

I am calling and running the following store procedure from vb.net.

CREATE   PROCEDURE dbo.uspSelectQueries  @msg1 varchar(3000) output
AS
Declare cSteps cursor  for
select New_Sql, table_Name, comment  from tblTotal
declare @SQL VARCHAR(500),  @tblName VARCHAR(300)

open cSteps
FETCH next from cSteps into @Sql, @tblName
while @@fetch_status = 0
begin
     exec(@sql)
    fetch next from cSteps into @sql, @tblName
     
end
close csteps
deallocate csteps
GO

the field New_Sql is a select statement with in my table and is ran with the exec(Qsql) statement which returns the results which I load to different datagrids. The problem I have is the field Table_Name is the name of the results. I want to name the table in the datagrid with this name. So the first query results should also pass Table_Name so I can set the table name in the grid.  The Only thing I can think of doing is storing passing the field Table_Name into a variable and using output parameter. But than I would have to substr or something like that to filter out each table name. Can I use an array within a strored Procedure or is there a way to pass the Table_name with the exec?  Thanks
MadIceAsked:
Who is Participating?
 
rafranciscoCommented:
open cSteps
FETCH next from cSteps into @Sql, @tblName
while @@fetch_status = 0
begin
    SELECT @tblName AS TableName --- This is what I added
     exec(@sql)
    fetch next from cSteps into @sql, @tblName
     
end
close csteps
deallocate csteps
GO

Try returning the table name as part of the result set.  Then in your VB.NET code, you know that the result sets are table name then data in sequence.
0
 
MadIceAuthor Commented:
Well that was cleaner than if I used output parameter and it works. Thanks Again...
0
 
rafranciscoCommented:
Glad to hear that it worked.
0
 
rafranciscoCommented:
Were you able to resolve this issue?
0
 
MadIceAuthor Commented:
I accepted this answer before...at least I thought I did.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.