• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Working with datasets

Alright here we go!! I'm writing an app and for that apps datastore I want to use a couple xml files. My vision is that when the app loads it reads the xml into a dataset that I work with while the app is running and then write that dataset back to xml upon closing the application, sounds simple enough right!! Here is where my idea goes downhill. I don't know how to "work" with the data in the dataset. Say I wanted to delete all records with say an "A" in the status field. If I were working against a database I'd say "delete * from table where status = A", how do I do that when referring to a dataset? Can I use a dataadapter that points to the dataset? Basically I would like to use sql against a dataset but have a feeling that can't be done. If so do I need to learn xquery or something of that sort.

Extreme appriciation to whomever is able to help me with this.
0
airwaysfreight
Asked:
airwaysfreight
1 Solution
 
Wim_BlCommented:
Hi,

an exhaustive way could be: once the dataset is filled, loop through the rows, check the desired item and delete the row if necessary, like:

dim dr as DataRow
for each dr in ds.tables("someTable").Rows
    if dr.item("someColumn") = ...
   ...
next

I have no knowlegde of more "advanced" techniques.  Practically, when using XML-data, I load the XML-file into a DOM-object and then work with this, in combination with all the methods that are provided with it to modify it's data (find node, delete node, add node, etc...) With XPath, you can use a sort of query language for this DOM-object. Finally, I save the entire DOM back to the file. I believe this may be a better solution for your type of problem.

greetings!
0
 
rrbeckerCommented:
Hi Wim_Bl,

(1) Do you have a way of loading the XML into your database?
(2) or Are you just  looking for a way to manipulate the data after it is stored?

rrbecker
0
 
rrbeckerCommented:
Hi Wim_Bl,

I read your question again, maybe I don't have anything to offer....

Sorry,

rrbecker
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
arif_eqbalCommented:
hi airwaysfreight

Well you can't use SQL with Datasets but you have better options still
say for eg. you need to Delete all records with Status=A

say you have filled in a Dataset DS like this

       DS.ReadXml("C:\ds.xml")

Then to Delete All rows with Status=A

        Dim DR As DataRow
        For Each DR In DS.Tables(0).Select("Status='A'")
            DR.Delete()
        Next

similarly you have all the possibilities with you
0
 
airwaysfreightAuthor Commented:
Hi arif_eqbal

Can I use multiple criteria in your example above?

Ex.
For Each DR In DS.Tables(0).Select("Status='A' or CustNumber=-'12345'")

Thanks
0
 
arif_eqbalCommented:
Yes of course
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now