By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Accessing DataAdapater tablename property

P: n/a
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"]

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/de...mnmappings.asp.

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

HTH

DalePres
MCAD, MCDBA, MCSE


"KimD" <Ki**@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
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"]

Nov 16 '05 #2

P: n/a
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" wrote:
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/de...mnmappings.asp.

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

HTH

DalePres
MCAD, MCDBA, MCSE


"KimD" <Ki**@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
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"]


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.