Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generic Data Access
Message
 
À
27/12/2008 13:01:46
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01369672
Message ID:
01369847
Vues:
10
Thanks Bonnie.

I implemented the code below, and it works fine. Thanks!



>>Ok, I'll give it a crack. There is another question on this that you hit upon.
>>
>>If I call a Sproc which pulls data from multiple tables, say in a JOIN, how does C#/ADO.Net know which tables to update changes to?

>
>When filling a DataSet from a Stored Proc that returns multiple tables, the DataAdapter automatically assumes table names of Table, Table1, Table2, etc. So, your DataSet either has to have those table names, OR you need to use the TableMapping that I mentioned below. We implement this in our Framework by having a SetTableMappings method in our DataSet classes. Our DataAccess.FillData() method calls it (and passes the DataAdapter object to it). Works quite well. =0)
>
>~~Bonnie
>
>
>
>
>>
>>
>>>>ya, ya, ya - I know. And I appreciate your patience. Believe it or not, I really am learning :)
>>>
>>>That's all I ask. =0)
>>>
>>>>The problem is that because I'm using the IDbDataAdapter interface, the Fill method on the adapter doesn't support a TableName value.
>>>
>>>OK, good question. Easy answer too. I personally don't have to worry about that in my class, because we always fill our entire DataSet (muliple tables if there are any) with Stored Procs that return multiple result sets if there any.
>>>
>>>But, if you want to allow a tablename to be passed so that you only fill that one table, then you can try this: include it as a parameter in your .FillData() method, and use the TableMappings property like this (this is un-tested code, but it should work):
>>>
>>>
>>>	protected bool FillData(DataSet ds, string StoredProcName, string TableName)
>>>	{
>>>		try
>>>		{
>>>			this.oCommand.CommandText = StoredProcName;
>>>			this.oAdapter.TableMappings.Clear();
>>>			if (TableName.Length != 0)
>>>				this.oAdapter.TableMappings.Add("Table", TableName);
>>>			this.oAdapter.Fill(ds);
>>>		}
>>>		catch (Exception ex)
>>>		{
>>>			this.ErrorMessage += ex.Message;
>>>			this.CloseConnection();
>>>			return false;
>>>		}
>>>		return true;
>>>	}
>>>
>>>
>>>~~Bonnie
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform