2

I know in .net datasets you can give names to the tables. Is there anyway to do this from Sql before you get the data back.

My problem is this, I have a Stored Procedure that returns 2 or 4 tables based on the input parameters so I had an If statement in there

' Verify that the expected results of two tables were return from the Stored Procedure
If (dsPosting.Tables.Count = 4 AndAlso intBankType <> 10) _
OrElse (dsPosting.Tables.Count = 2 AndAlso intBankType = 10) Then

Now the Stored Procedure has changed to 2 or 5 and the order is different. Is there a better way to identify I want "these two table" rather than hard coding the value in code and having to issue a new release.

Ideally I would like something like ds.Table("TheOneIWant") or something along those lines?

SysDragon
  • 9,692
  • 15
  • 60
  • 89
Mike
  • 5,918
  • 9
  • 57
  • 94
  • how are you filling the `DataSet`? – Ted Jun 05 '13 at 13:43
  • afaik, you can't do that from a stored procedure. Possible duplicate of http://stackoverflow.com/questions/589976/how-can-you-name-the-datasets-tables-you-return-in-a-stored-proc – Wim Ombelets Jun 05 '13 at 13:43
  • @Ted Microsoft Application Block `dsPosting = SqlHelper.ExecuteDataset` – Mike Jun 05 '13 at 14:59
  • Can't you store the `DataSet` in a `Session` or `ViewState` variable and use it for both the `ListView` and `GridView`? – Ted Jun 05 '13 at 17:01

1 Answers1

1

The successive separate result in TDS do not have names; they are just sequential grids of results. So no, there is no way to do this. Your code needs to know (or be able to deduce) what results it is expecting. One option might be to look at the schema of each as it comes back.

Another way of looking at this is to look at the line:

Now the Stored Procedure has changed to 2 or 5 and the order is different.

That is a breaking change; avoiding breaking changes is a really good idea.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • "That is a breaking change" Agreed, but the DB and .net departments are not always on the same page. I am looking at making it always the last two tables. – Mike Jun 05 '13 at 14:54