0

I create three stored procedure in MySQL. It's working fine. Now I read the third procedure using C#. It returns the two tables named table, table1. How can I assign name of the each tables? I'm really confused the tables name while using more than 8 or 10.

create procedure dbo.GetPeople
as
begin
    select * from dbo.Person;
end;

create procedure dbo.GetCars
as
begin
    select * from dbo.Car;
end;

-- This gives the same result as before
create procedure dbo.GetSomething
as
begin
    exec dbo.GetPeople;
    exec dbo.GetCars;
end;
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
user3085540
  • 275
  • 3
  • 12
  • 27

2 Answers2

0

In c# you you will get table from dataSet by index, because when we fill a dataSet from a dataBase then we never recieve table names from db.

One thing is passible as i used for reporting when i returning multiple tables by sp is that:

select an extra colum in each select statement that reprent table name.

e.g your sp

create procedure dbo.GetData
as
begin

select '' as 'Person', * from dbo.Person;
select '' as 'Car',* from dbo.Car;

end;

And do foreach loop on you dataSet to get firstColumn Name of each table as your DbTableName.
Following is dumy code please verify, i did't compile.

foreach(DataTable tbl in dataSet.Tables)
 {
       if(tbl.columns[0].name=="Person")
       {
        //your code to do with table Person
       }esle if(tbl.columns[0].name=="Car")
        //your code to do with table Car
       }
 }
Siddique Mahsud
  • 1,453
  • 11
  • 21
  • I am using sqlServer, working in sql server. re structure for you mysql – Siddique Mahsud Feb 18 '14 at 07:23
  • Suppose we have more than thousand means it show the first columns of thousand records show the table name right – user3085540 Feb 18 '14 at 07:31
  • Its not a right way, but just a possible way. I search more for my own but finally i work to apply this approach. 2nd is just access datatable by their index, perhaps already you are accessing like ds.Tables[0] ..ds.Tables[1] .. ds.Tables[2] – Siddique Mahsud Feb 18 '14 at 08:28
0
DataSet _ds=new DataSet();

DataTable _dtEmployee=new DataTable();

_dtEmployee=_ds.Tables["employee"];

or

_dtEmployee=ds.Tables[0]; 
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
Revan
  • 1,104
  • 12
  • 27