Results 1 to 13 of 13

Thread: Datasets and XML

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    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?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Check out the Datarow part of the dataset, that is probably what you are looking for.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    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?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    A Dataset is just a collection of datatables really. You would work with which ever table the data you want is in.

    VB Code:
    1. Dim ds As New Dataset()
    2. ds.ReadXMl("..\sample.xml")
    3. Msgbox(ds.tables(0).rows(0)("ColumnName").ToString)

  5. #5
    Lively Member
    Join Date
    Oct 2002
    Posts
    67
    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?

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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.

  7. #7
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124
    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!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    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..

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Ohh Edneeis,
    I can hardly contain my excitement If you're correct, I wasted alot of time and effort on my latest project *sigh*... I have dozens of Tabs and 100's of Textboxes/Labels on my form and I kept telling my self, GOD there has got to be an EASIER WAY. If you can slap some simple code that will allow me to tie a Class object into a datagrid, I will Love you forever! (Nothing sexual though!)

  11. #11
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Originally posted by Hinder
    Ohh Edneeis,
    I can hardly contain my excitement If you're correct, I wasted alot of time and effort on my latest project *sigh*... I have dozens of Tabs and 100's of Textboxes/Labels on my form and I kept telling my self, GOD there has got to be an EASIER WAY. If you can slap some simple code that will allow me to tie a Class object into a datagrid, I will Love you forever! (Nothing sexual though!)
    What kind of program are you building??

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    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..

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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
  •  



Click Here to Expand Forum to Full Width