DataSource/DataBind

T

ThunderMusic

Hi,
This question probably went back a couple of times, but I didn't find
anything about it on google, so I ask here...

What is the best way to use the DataSource/DataBind pattern in a class? I
would like the user to be able to set a data source and I'd like my class to
be able to use this datasource to build a DataTable I could use for further
processing...

Can it be done? if it can, how?

Thanks

ThunderMusic
 
T

ThunderMusic

I don't really understand what the purpose of the processing has to do with
how to set a datasource and converting it to a DataTable, but I don't mind
giving a little spoiler on what I'm doing (nobody won't know the overall of
the project just by this tiny bit anyway)

I must itterate in the rows and find some columns (colums names provided by
the user in a property of the object) and display the values of these
columns in graphs and charts...

I know that most bindable controls can receive Arrays, List, SortedList,
Dictionaries, DataTable, DataView, DataSet, et al. All thos controls don't
behave the same at all when it comes to retrieve the data, so I don't want
my objects to always try to find which object I'm working with... If
there's an easy way of doing it, I wanna know... I just don't want to do if
(datasource is DataSet) DoSomething; if (datasource is somethingelse)
DoSomethingElse; and so on... If I can't do without it, I'll do it, but if I
can do without, I'd prefer to do without... ;) and preferably I don't want
to inherit from DataBoundControl because I'm not developing a control yet...
the Data-Bound object is only a class that will be used in many of my
controls...

Thanks

ThunderMusic
 
C

Cor Ligthert [MVP]

Thundermusic,

In my idea are there only very few controls in WindowForms that can use the
datasource.

That are the ListControls, the DataGrid and the DataGridView
(complex datacontrols)

And that distinct them from the other controls which all can all however
only be binded using the DataBind.

Cor
 
M

Miro

Thunder,

I did something similar along what your looking for - ( I think. )

I have created a Class that has a couple properties:
Private DBName As String
Private TableName As String
Private FieldName As String
Private FieldType As String
Private FieldLength As Integer

and to make a long story short it allows me to call a sub that adds this
into an array of the class.
Setup_AddFields(DBFileName, "VersionTable", "VersionField", "StringType", 4)

I then have another sub that loops thru the array and creates the dbfile
name if it doesnt exist,
then it creates the table if it doesnt exist, and then it adds the field,
with the type and length.

Is that something that you are looking for ?

M.
 
T

ThunderMusic

ok, but this DataBind(), what does it do under the hood? I mean, must it
convert the object datasource into whatever it is in reality? (IEnumerable,
IList, et al.)

thanks

ThunderMusic
 
T

ThunderMusic

I dont really see how it can help me, but I'll try to find out...

thanks a lot for your help...

ThunderMusic
 

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

Top