Skip to content Skip to sidebar Skip to footer

How To Get The Dataset To Recognize The Table Names From Stored Procedure?

I have a stored procedures which returns about 5 tables and I am returning them something like this: select from Products where ProductId = @ProductId select

Solution 1:

It's actually possible, you just need to load the table scheme first, which contains no data but information about the table structure including table names:

adapter.FillSchema(dataset, SchemaType.Source);
adapter.Fill(dataset);

Seems this doesn't work on queries that are contained in the database (like you might use in MS Access), but it does the job for a regular table.

Solution 2:

You can't. The table name has no meaning in the result set because a query can contain many tables.

You should know what your resultsets are and should not have to derive table names.

Otherwise,

select'Products'AS ThisTable, <fields>from Products where ProductId =@ProductId

Or JOIN first and unpick later

Or define your dataset.xsd etc up front and map according.

Solution 3:

The only way to retrieve a table by name from a dataset is: if you name it when filling from an adapter or manually name them later one table at a time:

adapter.fill(dataset, "nameoftable")

now when you access the ds in the future you can access by name; ds.tables("nameoftable").rows etc.

or name them later.

_ds.tables(0).tablename = "nameoftable"

Post a Comment for "How To Get The Dataset To Recognize The Table Names From Stored Procedure?"