|
-
Jun 2nd, 2003, 10:48 AM
#1
Thread Starter
Hyperactive Member
Datasets and XML
How do I manipulate the data in a Dataset with pure code? I'm used to using a Recordset in VB6/ADO but it seems ADO.Net removed the recordset. I don't use a Database at all, I simply use a Dataset and a Datagrid and save/load to XML but I need to add, modify, and delete the data with just code. What object has replaced the Recordset? Is it a datacolumn?
-
Jun 2nd, 2003, 11:55 AM
#2
Check out the Datarow part of the dataset, that is probably what you are looking for.
-
Jun 2nd, 2003, 04:18 PM
#3
Thread Starter
Hyperactive Member
Thanks Edneeis, I looked up the Datarow object and it seems that the Datarow requires a DataTable to work with it, Is there anyways to use the Datarow directly with a Dataset?
-
Jun 2nd, 2003, 04:28 PM
#4
A Dataset is just a collection of datatables really. You would work with which ever table the data you want is in.
VB Code:
Dim ds As New Dataset()
ds.ReadXMl("..\sample.xml")
Msgbox(ds.tables(0).rows(0)("ColumnName").ToString)
-
Jun 2nd, 2003, 04:38 PM
#5
Lively Member
Ok heres a summary of what follows,, this is pseudo code, untested.
1. I create a dataset
2. i populate the dataset with a table a couple of columns and a row
3. i save the dataset to an xml file
4. i load the dataset from an xml file
remember, a dataset contains tables which contains columns, which (sort of) contains rows
'** create dataset manually
dim ds as datset("MyDataSet")
'** create table
Dim tbl As DataTable = ds.Tables.Add("Table")
'** Create column in table
Dim Name = tbl.Columns.Add("Name", GetType(String))
'** Create another column in table
Dim age = tbl.Columns.Add("Age", GetType(integer))
'*** How to add a row to the table tbl
Dim row As DataRow = tbl.NewRow()
row("Name") = "Fred"
row("Age") = 25
tbl.Rows.Add(row)
'*** how to save a dataset to an xml file
ds.WriteXml("c:\config.xml", XmlWriteMode.WriteSchema)
'*** how to load a dataset from an xml file.
ds.ReadXml("c:\config.xml")
This what you need?
-
Jun 2nd, 2003, 05:00 PM
#6
Frenzied Member
To make thing even easier, I would create the xml file in a text editor or in VS but leave it empty. That saves you the trouble of create datatables and datacoloumns.
-
Jun 2nd, 2003, 07:48 PM
#7
Lively Member
I'm quite puzzled that why we need XML to store data information since we can save the data in the dataset. I had reviewed quite a few articles about XML eXtensible Markup Language (can considered as a plain text file). And I know XML is platform independent, does it mean that almost all the software and hardware platform can view and access the XML data? Can anyone give me a good explaination why The XML is so important to the next generation of markup language. And what is the different when using traditional database(MS Access) and XML ?
thanks!
-
Jun 2nd, 2003, 08:11 PM
#8
Thread Starter
Hyperactive Member
I'm quite puzzled that why we need XML to store data information since we can save the data in the dataset.
Well I for one don't need a database or care to make one, XML seems to fit my needs.. I'm really just using the Dataset so I can Bind a Datagrid to it for easy data manipulation, in the end, My data will be nicely sorted into classes then placed inside hashtables. Kinda a long process but when you have classes that have 100+ variables in each one and many different classes, it gets kinda tough trying to build a editor with Text boxes and Labels.. I wish there was a way to Bind a class directly to a Datagrid, that would just solve all my problems all together..
-
Jun 2nd, 2003, 08:59 PM
#9
You CAN bind a class directly to a Datagrid. You can bind anything that Implements IList or one of its counter parts. IListSource is the simplest but it gives the fewest options and IBindableList has everything but the kitchen sink but of course is more work to implement. There are a few inbetween as well.
-
Jun 2nd, 2003, 09:07 PM
#10
Thread Starter
Hyperactive Member
-
Jun 2nd, 2003, 09:59 PM
#11
Frenzied Member
What kind of program are you building??
-
Jun 2nd, 2003, 10:18 PM
#12
Thread Starter
Hyperactive Member
Well I'm coding a Galaxy Editor for a online game working on. I'm halting further coding until I can figure out how to implement the binding of my classes directly to a datagrid. I searched the forums and the Internet for any help but everything I find is database related. As I mentioned before, I'm not using a database, I wish to simply take a Class object and Bind it directly to a datagrid for editing. I have tried to take my classes and .Add them to a ArrayList and then Datagrid.Datasource = AL but that doesn't produce any wanted results..
-
Jun 2nd, 2003, 11:56 PM
#13
The amount of work you'll need to do to implement the right interfaces may be more trouble than its worth with complex classes. Although maybe you could work out some sort of base class that does it that the other can inherit from.
As a general example make a standard collection that inherits from collectionbase (which implements IList) and you can bind to that already. If you implement IListSource you can stuff everything into an ArrayList in the GetList method. But if you need all the functionality then you'll need to have all collection type objects probably implement IBindableList, which can be some work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|