473,394 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

general DataTable questions

Hello everyone,

I have some general questions about the DataTable object, and how it
works. Moderately new to C#, I have plenty of texts describing the
language, but not so much to reference ADO.NET objects (only the MSDN
help files).

I have written a C# Class Library that is responsible for encapsulating
database information. All the objects work just fine for singleton
record insert, update, select, and delete operations. But now we are
looking at interacting with sets of records.

So my plan is to implement a List object for each of the types that I
have a singleton object for. So corresponding to MyObject would be
MyObjectList.

Now I have lots of options of how to handle MyObjectList, and this is
where my questions about the DataTable come into play. In general I
know that each list will have a set of criteria properties, and methods
that can be used to get a set of records from the database. But as for
how to store those in memory ... here's what I've come up with so far:

1) I could simply make a member property of the MyObjectList class as
an array of MyObject classes, built from results of the database call.
Should work just fine, but doesn't seem to be taking advantage of all
the spiffy .NET interoperability (such as DataBinding).

2) I could simply keep a pointer to an SqlDataReader of the information
from the database call. The caller would be responsible for reading
through the records, storing it, and then calling some kind of
Connection Cleanup function on the MyObjectList class to clean up all
the connections that had to stay open while the data was being read.
Don't like this one, simply because it keeps resources tied up for an
indeterminate period of time.

3) I could read all the data out of the DataReader into a DataTable
member of the MyObjectList class. And herein lay my questions. How does
the DataTable class actually work? From samples I've seen where it can
be used to both read and write information to the database table, it
seems like there is some kind of persisted, underlying connection
between the DataTable and the database? Is this true? Does this operate
like a cursor then, where the database records are considered locked in
some fashion while the DataTable exists?

In general I want a set of data to be read-only, like a report. Records
can be updated, but only one at a time, and they would be saved
individually, separately from the list (which is handled perfectly by
the List-As-Array-of-Classes approach). This is similar to what I've
seen in some examples where a DataGrid control is DataBound to a
DataTable, and there is an EditItem command to update a single row.
Would this have similar results to what I've described earlier in this
paragraph?

Any tips or suggestions on how to handle sets of records in this fairly
simple model would be greatly appreciated. I'm sure I didn't include as
much information as you each might need, but it's abstract enough that
I wasn't sure what would be useful. Just let me know if there's any
questions.

Thanks a lot for any help,

Jason

Nov 17 '05 #1
1 1786
ng
Jason,

A datatable by itself is not connected to the underlying database. It's
almost like using the old recordset object without a connection object
still open. You can populate a dataset, which holds the datatable, work
with the data in your program, and then use an update or append query
for the database portion. Unfortunately, this is the only way I've used
datasets - I don't like having a persistent open connection.

If you want to really see how ado.net functions, O'Reilly has a great
book called ADO.NET Cookbook.

Tom
jason wrote:
Hello everyone,

I have some general questions about the DataTable object, and how it
works. Moderately new to C#, I have plenty of texts describing the
language, but not so much to reference ADO.NET objects (only the MSDN
help files).

I have written a C# Class Library that is responsible for encapsulating
database information. All the objects work just fine for singleton
record insert, update, select, and delete operations. But now we are
looking at interacting with sets of records.

So my plan is to implement a List object for each of the types that I
have a singleton object for. So corresponding to MyObject would be
MyObjectList.

Now I have lots of options of how to handle MyObjectList, and this is
where my questions about the DataTable come into play. In general I
know that each list will have a set of criteria properties, and methods
that can be used to get a set of records from the database. But as for
how to store those in memory ... here's what I've come up with so far:

1) I could simply make a member property of the MyObjectList class as
an array of MyObject classes, built from results of the database call.
Should work just fine, but doesn't seem to be taking advantage of all
the spiffy .NET interoperability (such as DataBinding).

2) I could simply keep a pointer to an SqlDataReader of the information
from the database call. The caller would be responsible for reading
through the records, storing it, and then calling some kind of
Connection Cleanup function on the MyObjectList class to clean up all
the connections that had to stay open while the data was being read.
Don't like this one, simply because it keeps resources tied up for an
indeterminate period of time.

3) I could read all the data out of the DataReader into a DataTable
member of the MyObjectList class. And herein lay my questions. How does
the DataTable class actually work? From samples I've seen where it can
be used to both read and write information to the database table, it
seems like there is some kind of persisted, underlying connection
between the DataTable and the database? Is this true? Does this operate
like a cursor then, where the database records are considered locked in
some fashion while the DataTable exists?

In general I want a set of data to be read-only, like a report. Records
can be updated, but only one at a time, and they would be saved
individually, separately from the list (which is handled perfectly by
the List-As-Array-of-Classes approach). This is similar to what I've
seen in some examples where a DataGrid control is DataBound to a
DataTable, and there is an EditItem command to update a single row.
Would this have similar results to what I've described earlier in this
paragraph?

Any tips or suggestions on how to handle sets of records in this fairly
simple model would be greatly appreciated. I'm sure I didn't include as
much information as you each might need, but it's abstract enough that
I wasn't sure what would be useful. Just let me know if there's any
questions.

Thanks a lot for any help,

Jason

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bodil, Norway | last post by:
Hi, I can't use DataTable! I try to write: Dim myDataTable As DataTable = New DataTable("ParentTable") I then get "Type expected" for the DataTable (in Task List) I have included "Imports...
9
by: pankaj_wolfhunter | last post by:
Hi, I need some clearance on the following questions: 1) Does LOAD command updates indexes defined for a table? 2) Is REPLACE option in the LOAD command a logged operation? Help will be...
8
by: Buddy | last post by:
Hello, We are using DataTable to store our data that we retrieve from SQL because it provides us with ROW/COLUMN concept. Due to DataTable been memory hungary we are finding that at least 40MB...
3
by: Matthew Wieder | last post by:
I have a datatable as a source and I need to produce a datatable which is all the rows in the original datatable except the first row, copied n times. So, if I had a datatable of: A B C...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
10
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I...
1
by: George | last post by:
Hi, I have a DataGridView, bounded to a DataTable which is populated/updated by a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds familiar to some of you ... I have...
6
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to...
0
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.