Accessing DataAdapater tablename property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm filling a dataset with the return of a stored procedure. The dataset
contains a number of tables which I am naming within the stored procedure,
however when I try to access the tables using the names assigned I get
errors. It doesn't seem to be assigning the names correctly within the stored
procedure - instead it uses default names: Table, Table1 etc.

e.g. Accessing using aDataSet.Tables["some tablename"]
 
Use the TableMappings.Add() method of the DataAdapter, like this:

sqlDA.TableMappings.Add("Table", "MyFirstTableName");
sqlDA.TableMappings.Add("Table1", "MySecondTableName");
sqlDA.TableMappings.Add("Table2", "MyThirdTableName");

Then you can access the tables like:

dataSet.Tables["MySecondTableName"]

You can read more about it at
http://msdn.microsoft.com/library/d...cpconsettingupdatatabledatacolumnmappings.asp.

You might also want to consider a strongly-typed DataSet.

HTH

DalePres
MCAD, MCDBA, MCSE
 
I think this approach works when you know the order and number of tables
being returned from the stored procedure. However in my case I do not know at
the point of calling the SP how many tables will be returned.

DalePres said:
Use the TableMappings.Add() method of the DataAdapter, like this:

sqlDA.TableMappings.Add("Table", "MyFirstTableName");
sqlDA.TableMappings.Add("Table1", "MySecondTableName");
sqlDA.TableMappings.Add("Table2", "MyThirdTableName");

Then you can access the tables like:

dataSet.Tables["MySecondTableName"]

You can read more about it at
http://msdn.microsoft.com/library/d...cpconsettingupdatatabledatacolumnmappings.asp.

You might also want to consider a strongly-typed DataSet.

HTH

DalePres
MCAD, MCDBA, MCSE




KimD said:
I'm filling a dataset with the return of a stored procedure. The dataset
contains a number of tables which I am naming within the stored procedure,
however when I try to access the tables using the names assigned I get
errors. It doesn't seem to be assigning the names correctly within the
stored
procedure - instead it uses default names: Table, Table1 etc.

e.g. Accessing using aDataSet.Tables["some tablename"]
 
Back
Top