Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

Reflection: accessing member of given object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andreas.Knudsen(AT)bekk.no - 09 May 2005 14:08 GMT
Hi, I have trouble finding info on the following:

I have an object myDataAccessObject that contains heaps of SQLDataAdapters
and derivatives thereof. These are auto-generated for me by VS.

I want to be able to call the update-method on all of these (in effect doing
a database-dump) with myDataSet as input (since that's where my data is).

now I *could* put all the adapters into a list and loop through them,
calling the update method, but that's not pretty and I will have to manage
that list as the DB expands so I don't want to do that.

basicly I want to:

-get all sqladapters from myObject
-call "Update" with parameter myDataSet on all of them

that shouldn't be so hard, yet I am stuck and am finding no docs on it.

yours
Andreas Knudsen
Jorge L Matos [MCSD.NET] - 09 May 2005 17:54 GMT
Andreas,

I haven't tested the following code, but it *should* work.

Type typeToUse = objectToUse.GetType();
foreach(PropertyInfo pi in typeToUse.GetProperties(BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
{
 if (pi.PropertyType == typeof(SqlDataAdapter))
 {
   SqlDataAdapter da = pi.GetValue(objectToUse, new object[0]) as
SqlDataAdapter;
  da.Update(myDataSet);
 }
}

> Hi, I have trouble finding info on the following:
>
[quoted text clipped - 17 lines]
> yours
> Andreas Knudsen
Andreas.Knudsen(AT)bekk.no - 23 May 2005 10:17 GMT
Thanks for answer ,but:

> Andreas,
>
> I haven't tested the following code, but it *should* work.
>
> Type typeToUse = objectToUse.GetType();

which object would "objectToUse" be?
would that be the class that contains several sqlDataAdapters?
would that be a null object in which to place the dataadapter once it is
located using reflection?

or do you presume that objectToUse is the adapter that I am looking for?

yours
Andreas
Jorge L Matos [MCSD.NET] - 23 May 2005 18:12 GMT
"objectToUse" is the object that cotains the SqlDataAdapter objects as
properties.  

For example:

class MyDataAccessObject
{
 
SqlDataAdapter PubsAdapter
{
   get {[omitted code]}
   set {[omitted code]}
}

SqlDataAdapter NorthWindAdapter
{
   get {[omitted code]}
   set {[omitted code]}
}
}

Signature

Jorge L. Matos

> Thanks for answer ,but:
>
[quoted text clipped - 13 lines]
> yours
> Andreas

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.