DataGrid.Binding()

  • Thread starter Thread starter Just D
  • Start date Start date
J

Just D

Hi,

If anybody needs to show some data retrieved from the database table, what
method is more preferrable?

1. DataSet ds = ...;
DataGrid.Data.Source.ds;
DataGrid.Bind();

2. Write a custom object, fill it with the DataSet data and ÅÒÕÔ try to bind
the DataGrid or DataTable and this custom object?

I usually don't allow users to change anything irectly in the DataGrid, but
I allow to select a row and then show a set of TextBoxes, DropDown lists
etc. to correct/enter data. Is it a good approach or it's better to allow
userworking with the DataGrid directly and then Update this DataSet or
whatever?

Thanks,
Dmitri
 
Dmitri,
It really depends on what you are doing. I, for instance, steer away
from the DataSet object. I usually don't have a need for its features. A
dataset is very useful if you need to have several tables linked together in
a parent/child relationship or in some other fashion. When I need to bind
data, I find that I have a single set of data. If I were to use the dataset
for this, I would be creating an object with more overhead than I need. I
usually have a custom object for every entity that I work with, so I would
just use a datareader from the database to create a collection of these
objects. If your data is very simple, you could just create an array of
strings to which to bind. Bindable controls can bind to any object that has
primitive public properties such as string and int.

Also, in question number 2, you are confusing a web control with an ADO.NET
object. You cannot bind a DataTable with a custom object. A DataTable is a
container object commonly used within a DataSet. A Datagrid can be bound TO
a DataTable or other custom object or simply an array. Check out the SDK
documentation on databinding.

Best regards,
Jeffrey Palermo
 
Hi Jeffry,
Also, in question number 2, you are confusing a web control with an
ADO.NET
object. You cannot bind a DataTable with a custom object. A DataTable is
a
container object commonly used within a DataSet. A Datagrid can be bound
TO
a DataTable or other custom object or simply an array. Check out the SDK
documentation on databinding.

You know, maybe the second part of the question was not correct. Thanks that
you corrected me.

What about the first question? If you receive data from a few database
tables using subqueries, JOIN, many other tricks, then do you parse this
information to your custom objects loading the whole data into your own
object and then deleting the original DataSet? Ok, I can imagine that, but
if you need to save the changes, made by user, then you need to compare what
has been changes, so you need flags in every sub object to detect if this
data is dirty and finally write this data? What do you think if you use a
database view to retrieve this complex data instead and save data back to
this view? In this case you could use the same DataSet to show and save a
changed data and use DataAdapter.Update() any headache. Is it good or bad?
Or I don't see something obvious? Maybe the custom objects are always
better?

Thanks,
Dmitri
 
Dmitri,
In the case that you just described, it would be very easy to use a
dataset to automate your updates back to the database, so you can use that
method.

Best regards,
Jeffrey Palermo
 

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

Back
Top