Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filling tables in a dataset
Message
De
17/05/2006 20:42:52
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01123034
Message ID:
01123071
Vues:
26
This message has been marked as the solution to the initial question of the thread.
Einar,

You have a couple different options for filling a Typed DataSet.

A Stored Proc will always return your tables with the names: table, Table1, Table2, etc. Typically you are not going to want to reference the tables that way in your DataSet. There are two ways around this problem.

1) You can define your DataSets with whatever tablenames you need, and then when you fill the DataSet, you can use the DataAdapter.TableMappings.Add( ) method to map table to CustomerInfo, Table1 to CustomerAddress, etc. prior to filling the DataSet from the DataAdapter (Kevin likes to use this methodology).

2) The second option is to define your DataSets with the names table, Table1, Table2, etc. just like the Stored Procs will use when the DataSets are filled. Then, further sub-class the generated Typed DataSet and have a property for each table that in effect renames your table (I prefer this way instead).

~~Bonnie



>Thanks Eric. Could you give me a simple example of a SP that returns two result sets? Oh an by the way my dataset is a typed dataset, is the adapter smart enough to figure out which result set to use in which table?
>
>Thanks,
>Einar
>
>>if your dataset has 2 tables, you can set the TableName property:
>>
>>SqlDataAdapter adapter1 = new SqlDataAdapter("YourSPThatReturnsMultipleResultSets", sqlConnection);
>>adapter1.Fill(myDataSet);
>>myDataSet.Tables[0].TableName = "Table1Name";
>>myDataSet.Tables[1].TableName = "Table2Name";
>>
>>
>>>I have a dataset with two tables. I know I can fill the tables independently using a a data adaper for each of the tables. Something like this:
>>>
>>>MyDataSet myDataSet = new MyDataSet();
>>>
>>>SqlDataAdapter adapter1 = new SqlDataAdapter("SP1", sqlConnection);
>>>adapter1.Fill(myDataSet, myDataSet.Table1.TableName);
>>>
>>>SqlDataAdapter adapter2 = new SqlDataAdapter("SP2", sqlConnection);
>>>adapter2.Fill(myDataSet, myDataSet.Table2.TableName);
>>>
>>>(I think that code would compile <s>)
>>>
>>>Anywho is there a way to construct a stored procedure to return multiple "datasets" so that I can fill both Table1 and Table2 using one stored procedure? (maybe Table1 is the parent table and Table2 is the child table)
>>>
>>>How do you do this?
>>>
>>>Thanks,
>>>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform