Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with CommandBuilder
Message
De
29/11/2004 17:14:20
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00965146
Message ID:
00965545
Vues:
12
Gerard,

They are different because you've already defined oAd in your declarations at the top of your class:
protected OleDbDataAdapter oAd;
That makes this.oAd a variable that can be used throughout your class (but it hasn't as yet been instantiated). When you instantiated oAd in your GetData() method with:
OleDbDataAdapter oAd = new OleDbDataAdapter(this.sSelectString ,oCon);
you are, in effect, creating another variable that is local to the GetData() method and this is not the same as the oAd that was created in the declarations of your class (which is referenced by this.oAd and is scoped globally to the entire class).

By replacing the command as I suggested, you are now instantiating the variable that is scoped to the entire class, rather than one that is scoped only to the method. And, you *do* need this class-scoped variable since you are using it in two different methods.

Do you see the difference between the two now or do I need to explain it differently?

~~Bonnie



>Hi Bonnie. Many thanks for your reply.
>That sorted the problem but I dont understand why !!
>
>OleDbDataAdapter oAd = new OleDbDataAdapter(this.sSelectString ,oCon);
> replaced by
>this.oAd = new OleDbDataAdapter(this.sSelectString ,oCon);
>
>Why is there a difference then between the two commands ?
>Are they both not initialising a New OleDbDataAdapter called oAd ?
>
>Regards,
>
>Gerard
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