Searching for an object in a component

Y

YunusEmre

Hi,

I have a class named MyDataAdapter that derives from
System.ComponentModel.Component and it contains all of my SqlDataAdapter
objects(around a 100).

How can I find a SqlDataAdapter in the MyDataAdapter instance at run-time by
its name.

e-mre
 
M

Marina

Have MyDataAdapter add all the adapters to a private hashtable by name. So
something like:

myHashTable.Add("adapter1",adapter1)
....

Then right a method to just retrieve the right adapter out of the hashtable
by name.
 
Y

YunusEmre

Sounds like a solution but there must a better way. I mean I was expecting
to see something like
component.Findcontrol("aaa")
But I couldn't find anything like this.

e-mre
 
M

Marina

I don't think that's going to happen for components. This is compiled code,
it just doesn't work like that - the way interpreted javascript does.

By the way, if it did work that way, it would be pretty slow, because it
would have to involve reflection. You can write it that way using
reflection, but it's going to be a ton more code then the method I
suggested, and much slower.
 
Y

YunusEmre

While thinking I came to realize that MyDataAdapter does not have to be a
component. I am not using anything specific to component class.
It can be a control or something else .. I don't know.

Can this lead me to another solution.?

e-mre
 
M

Marina

No. I just explained why.

The FindControl is only something in asp.net, because when the .aspx or
..ascx is parsed, asp.net can pick up those controls by name.

You just can't do that for arbitrary variables.

I didn't ask before, but is it really necessary to create 100 data adapters
all at once? There have to be better ways to accomplish what you want.
 
Y

YunusEmre

I am afraid yes. Each DataAdapter is used for operating on a table and I
have a huge database.I prepare all the DataAdapters at design-time and
generate DataSet tables for them also at design time.

Now I am trying to do the HashTable solution you've proposed earlier. I
guess it will do the job.
 
M

Marina

In my opinion this is very poor design. You should be writing your own data
access code, in a generic enough manner, that you can update any table you
need to by calling a few methods.

You should not be using the design time wizard to generate 100 objects. My
opinion is that the wizard is a good learning tool and a way to get started,
but should not be used to design real applications.

I would recommend throwing it all away, and writing all the code yourself.
Once you write the update logic once, you should be able to update any set
of data that you have, if you have written it generically. In your current
model, you need to keep all the adapters in sync, and do all this work when
you add new ones.
 
Y

YunusEmre

I am afraid it is too late for the change. But thanx for the advice. I will
consider it on my next project.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top