473,399 Members | 4,177 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,399 software developers and data experts.

About using DataRow...

When I initialize my program I need to load from several sources of data
from files which are in a table form- in each set of data they share fields
(like say name address phone). I used to load them into a Hashtable keyed by
ID where the value is a class that has all the fields required (name,
address, etc...)

Now after discovering the power of DataTables and DataGrids I have decided
to load my data into that format instead, but much of my program still
depends on those concrete classes I had which had those fields and methods
specific to the data I load. With DataTables, that data had to be loaded into
this abstract DataRow which has no methods or fields specific to the data. So
now I'm wondering should I still keep my Hashtable of classes (Which begs the
question: when loading a DataRow does it actually copy my data from my
Hashtable or does it reference it?) or is there a way to customize DataRow so
I can have those specific fields and methods in the DataTable so I can get
rid of this HAshtable?
Nov 16 '05 #1
6 7084
MrNobody,

I would say create a typed data set. You can use the designer to create
the data set structure in the editor, and then it will create a strongly
typed data set (with properties that you can access instead of using field
lookups). It should help with this sort of transition, and help reduce the
amount of code that you need to change.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MrNobody" <Mr******@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
When I initialize my program I need to load from several sources of data
from files which are in a table form- in each set of data they share
fields
(like say name address phone). I used to load them into a Hashtable keyed
by
ID where the value is a class that has all the fields required (name,
address, etc...)

Now after discovering the power of DataTables and DataGrids I have decided
to load my data into that format instead, but much of my program still
depends on those concrete classes I had which had those fields and methods
specific to the data I load. With DataTables, that data had to be loaded
into
this abstract DataRow which has no methods or fields specific to the data.
So
now I'm wondering should I still keep my Hashtable of classes (Which begs
the
question: when loading a DataRow does it actually copy my data from my
Hashtable or does it reference it?) or is there a way to customize DataRow
so
I can have those specific fields and methods in the DataTable so I can get
rid of this HAshtable?

Nov 16 '05 #2

Thanks for your advice!

I went into Design Mode and found the DataSet control in the toolbar- is
this whaat you meant? I tried creating one but when I want to do a typed
DataSet it needs a reference to one already in my project- of course this
dropdown is empty- what are the requirements so I can find my custom DataSet
in there? I created my DataTable programmatically, not via the Editor.

Or perhaps is there tutorial link you might know of off-hand to get me
started on this?

I am still not comfortable using the Data classes, as there's still a lot I
do not know, and any tutorials I find are based on untyped data loaded from a
database
Nov 16 '05 #3
You have to right click on your project, add new, and then select
dataset - then you can refrence the dataset with the dataset that you
actually place in your design view.
Nov 16 '05 #4


"Benny Raymond" wrote:
You have to right click on your project, add new, and then select
dataset - then you can refrence the dataset with the dataset that you
actually place in your design view.


Ok, so I do that and I create this empty DataSet, which does appear in that
dropdown now. But now how do I make this DataSet a strongly typed equivalent
to my old data classes?

Let's assume my data is name and address. My old class had those two fields
plus some methods to do some specific manipulation. How do I get this DataSet
to similate that?

On that DataSet editor, I only see XML related stuff on the toolbox, I don't
see how I can get it to describe my data or add properties so it is specific
to my data.

Thanks again for the help, boh of you!
Nov 16 '05 #5
Ok, I was playing around with it and it looks look I do have to use those XML
elements to describe my data. I added 3 SimpleTypes- 2 strings and 1 int.
After you create a type the rows beneath it are for adding data directly
right?

So now I'm not sure how to load my data using this new DataSet. I used to
create a DataTable which required creating specific columns. Then I'd start
reading from my file and for each record I'd have to call CreateRow and
AddRow on the DataTable.

How would I do this now with a strongly typed DataSet ? Aren't DataSets one
level above a table?
Nov 16 '05 #6
Hi,

Why don't you use casting instead of strong types?
you can:

DataRow dr = table.Rows[0];
string name = (dr["name"] as string).ToString(); // example method, you can
use any other method of any other cast
int number = (dr["number"] as int).CompareTo(0); // example method, you can
use any other method of any other cast

or you can:

string name = (string)dr["name"];
int number = (int)dr["number"];

Won't it work for you?

Tomer.

"MrNobody" <Mr******@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Ok, I was playing around with it and it looks look I do have to use those
XML
elements to describe my data. I added 3 SimpleTypes- 2 strings and 1 int.
After you create a type the rows beneath it are for adding data directly
right?

So now I'm not sure how to load my data using this new DataSet. I used to
create a DataTable which required creating specific columns. Then I'd
start
reading from my file and for each record I'd have to call CreateRow and
AddRow on the DataTable.

How would I do this now with a strongly typed DataSet ? Aren't DataSets
one
level above a table?

Nov 16 '05 #7

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

Similar topics

1
by: Piyush Gupta | last post by:
Hi All, I am using following code snippet to add another user in Users.xml: ------------------------------------------------------------------- DataSet dstUsers = new DataSet();...
4
by: Wes | last post by:
I want to use a DataGrid and manually populate the data in the table. Does anyone know how this is done?? I want to create all the Columns, and then just add rows as my Program runs. Is there...
4
by: rodchar | last post by:
Code Snippet 1 public class CustomerInfoCollection : IList { private ArrayList m_alCustomerInfo; private DataSet m_ds; public CustomerInfoCollection() {
0
by: Kelvin | last post by:
Hi All, I don't why I can't insert new rows between rows, and it can append on buttom record of datatable. With reference my code, Using Rows.InserAt or Rows.Add() is the better. Please advise....
7
by: Adrian Parker | last post by:
'function to convert null to nothing Function CheckDate(ByVal DRow As DataRow, ByVal strCol As String) As Date If DRow.Item(strCol) Is System.DBNull.Value Then Return Nothing Else Return...
4
by: Luqman | last post by:
Hi, Is it possible to use Field Names with Data Row. for example: Dim dr As DataRow = CType(Me.ProductsBindingSource.Current, DataRow) dr.ProductID=123 dr.ProductName="ABC"...
1
by: J055 | last post by:
Hi I have a Business class called User which returns a DataRow for individual user accounts using accountID as a parameter (i.e. User.Retrieve(accountID)). The ObjectDataSource doesn't complain...
5
by: samoore33 | last post by:
I use the code below to search through a DataSet: Dim t As DataTable t = result.Tables("State") Dim strExpr As String strExpr = "id = '" & theState.ToString() & "'" Dim foundRows() As DataRow...
5
by: jehugaleahsa | last post by:
Hello: I am trying to find what is the very best approach to business objects in Windows Forms. Windows Forms presents an awesome opportunity to use DataTables and I would like to continue doing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.