Best way to store dataset to disk???

P

processoriented

I am trying to find the best approach to do something here...
situation is this... One of the tables in my dataset is a "Work Order"
table with information about what needs to be done and where. Say my
user goes on site to do the work associated with the work order, and
while he is there, he discovers that the customer's phone number has
changed. Should be no problem, he opens up the app, looks at his list
of open work orders, finds the work order in question, and changes the
phone number. When he re-connects to the network and has access to the
database, the app just updates the work order table with the new phone
number. This is pretty simple, on the initial download to the user's
machine, I just store the work order table (along with everything else
in the dataset) to an xml doc like this:

Dim ds as New DataSet
' code to connect to database and fill the dataset goes here
ds.writexml(strFolder & "app_data.xml", XmlWriteMode.WriteSchema)


Great... user then turns off his machine, goes out to the customer's
site and realizes that the phone number needs to be changed... now when
he turns on his computer and fires up the application, it needs to show
him a list of his open work orders... again, this is simple:

Dim ds as New DataSet
ds.readxml(strFolder & "app_data.xml",XmlReadMode.ReadSchema)
'Code to parse through the dataset and display the relavant information
goes here...

Now that my user can see and modify all his open work orders, my code
will let him make modifications like this...

'This code appears in the btnSubmitChanges Click event
Dim tblToModify as DataTable = ds.tables("WorkOrders")
Dim rowToModify as DataRow = tblToModify.Rows.Find(strRowKey)
rowToModify.Items("Phone") = strNewPhoneNumber
'....
ds.writexml(strFolder & "modified_data.xml", XmlWriteMode.DiffGram)

Fantastic! Now my dataset has a record, not only of what the new phone
number is, but what it used to be, and I can use the rowstate
properties to look at both sets of information... but here is where I
am confused:
I can save the changes with a DiffGram style XML doc, but then what do
I do with the original XML doc and the DiffGram when I get back
on-line?

Moreover, what happens if my user switches off the computer and
switches it back on? Sure the computer has a record of the modified
data in the diffgram xml doc, but the code isn't looking there to show
him his list of open work-orders.

Basically what I am asking is this: I have my base data and my
modifications stored in a couple of XML docs, but how do I take the
information in those two xml docs and turn them back into the same
dataset I had right after my user made his changes? Or, should it
really be two different documents? Is there a way to do it in one
document? What happens if the user makes multiple modifications to the
data, turning on and off the computer in between each modification
prior to sending those changes back to the database?
 
S

susiedba

store it in a database; jackass

I am trying to find the best approach to do something here...
situation is this... One of the tables in my dataset is a "Work Order"
table with information about what needs to be done and where. Say my
user goes on site to do the work associated with the work order, and
while he is there, he discovers that the customer's phone number has
changed. Should be no problem, he opens up the app, looks at his list
of open work orders, finds the work order in question, and changes the
phone number. When he re-connects to the network and has access to the
database, the app just updates the work order table with the new phone
number. This is pretty simple, on the initial download to the user's
machine, I just store the work order table (along with everything else
in the dataset) to an xml doc like this:

Dim ds as New DataSet
' code to connect to database and fill the dataset goes here
ds.writexml(strFolder & "app_data.xml", XmlWriteMode.WriteSchema)


Great... user then turns off his machine, goes out to the customer's
site and realizes that the phone number needs to be changed... now when
he turns on his computer and fires up the application, it needs to show
him a list of his open work orders... again, this is simple:

Dim ds as New DataSet
ds.readxml(strFolder & "app_data.xml",XmlReadMode.ReadSchema)
'Code to parse through the dataset and display the relavant information
goes here...

Now that my user can see and modify all his open work orders, my code
will let him make modifications like this...

'This code appears in the btnSubmitChanges Click event
Dim tblToModify as DataTable = ds.tables("WorkOrders")
Dim rowToModify as DataRow = tblToModify.Rows.Find(strRowKey)
rowToModify.Items("Phone") = strNewPhoneNumber
'....
ds.writexml(strFolder & "modified_data.xml", XmlWriteMode.DiffGram)

Fantastic! Now my dataset has a record, not only of what the new phone
number is, but what it used to be, and I can use the rowstate
properties to look at both sets of information... but here is where I
am confused:
I can save the changes with a DiffGram style XML doc, but then what do
I do with the original XML doc and the DiffGram when I get back
on-line?

Moreover, what happens if my user switches off the computer and
switches it back on? Sure the computer has a record of the modified
data in the diffgram xml doc, but the code isn't looking there to show
him his list of open work-orders.

Basically what I am asking is this: I have my base data and my
modifications stored in a couple of XML docs, but how do I take the
information in those two xml docs and turn them back into the same
dataset I had right after my user made his changes? Or, should it
really be two different documents? Is there a way to do it in one
document? What happens if the user makes multiple modifications to the
data, turning on and off the computer in between each modification
prior to sending those changes back to the database?
 
R

Ryan S. Thiele

Create 2 datasets then merge them

Dataset1.Merge(Dataset2)

Try this


--
Thiele Enterprises - The Power Is In Your Hands Now!

--
I am trying to find the best approach to do something here...
situation is this... One of the tables in my dataset is a "Work Order"
table with information about what needs to be done and where. Say my
user goes on site to do the work associated with the work order, and
while he is there, he discovers that the customer's phone number has
changed. Should be no problem, he opens up the app, looks at his list
of open work orders, finds the work order in question, and changes the
phone number. When he re-connects to the network and has access to the
database, the app just updates the work order table with the new phone
number. This is pretty simple, on the initial download to the user's
machine, I just store the work order table (along with everything else
in the dataset) to an xml doc like this:

Dim ds as New DataSet
' code to connect to database and fill the dataset goes here
ds.writexml(strFolder & "app_data.xml", XmlWriteMode.WriteSchema)


Great... user then turns off his machine, goes out to the customer's
site and realizes that the phone number needs to be changed... now when
he turns on his computer and fires up the application, it needs to show
him a list of his open work orders... again, this is simple:

Dim ds as New DataSet
ds.readxml(strFolder & "app_data.xml",XmlReadMode.ReadSchema)
'Code to parse through the dataset and display the relavant information
goes here...

Now that my user can see and modify all his open work orders, my code
will let him make modifications like this...

'This code appears in the btnSubmitChanges Click event
Dim tblToModify as DataTable = ds.tables("WorkOrders")
Dim rowToModify as DataRow = tblToModify.Rows.Find(strRowKey)
rowToModify.Items("Phone") = strNewPhoneNumber
'....
ds.writexml(strFolder & "modified_data.xml", XmlWriteMode.DiffGram)

Fantastic! Now my dataset has a record, not only of what the new phone
number is, but what it used to be, and I can use the rowstate
properties to look at both sets of information... but here is where I
am confused:
I can save the changes with a DiffGram style XML doc, but then what do
I do with the original XML doc and the DiffGram when I get back
on-line?

Moreover, what happens if my user switches off the computer and
switches it back on? Sure the computer has a record of the modified
data in the diffgram xml doc, but the code isn't looking there to show
him his list of open work-orders.

Basically what I am asking is this: I have my base data and my
modifications stored in a couple of XML docs, but how do I take the
information in those two xml docs and turn them back into the same
dataset I had right after my user made his changes? Or, should it
really be two different documents? Is there a way to do it in one
document? What happens if the user makes multiple modifications to the
data, turning on and off the computer in between each modification
prior to sending those changes back to the database?
 
P

processoriented

Hi Ryan,

Thanks... I was just thinking something along those lines... I will
experiment and let you know how it goes.
 
P

processoriented

Hi Again Ryan,

I tried to come up with a simple Console App that would test the merge
function... and got these results...

Dim strConn, strSQL As String
Dim ds As New DataSet()
Dim strMode As String
strMode = "Load"
strMode = "Modify"
strMode = "Review"

Select Case strMode
Case "Load"
strConn = "Data Source=(local);" & _
"Initial Catalog=Northwind;Integrated
Security=True;"
strSQL = "SELECT TOP 3 CustomerID, CompanyName FROM
Customers"
Dim da As New SqlDataAdapter(strSQL, strConn)
da.Fill(ds, "Customers")

ds.WriteXml("C:\MyData.xml", XmlWriteMode.WriteSchema)
Console.WriteLine("Loaded")
Case "Modify"
ds.ReadXml("C:\MyData.xml", XmlReadMode.ReadSchema)
ds.AcceptChanges()
Dim tbl As DataTable = ds.Tables("Customers")
tbl.Rows(1)("CompanyName") = "Modified Company Name"
tbl.Rows(2).Delete()
tbl.Rows.Add("NEWCO", "New Company Name")
Dim intIndex As Integer = 0
For Each row As DataRow In tbl.Rows
Console.WriteLine("Row {0} - {1}", intIndex,
row.RowState)
intIndex = intIndex + 1
Next
ds.WriteXml("C:\MyData_dg.xml", XmlWriteMode.DiffGram)
Case "Review"
ds.ReadXml("C:\MyData.xml", XmlReadMode.ReadSchema)
ds.AcceptChanges()
If
My.Computer.FileSystem.FileExists("C:\MyData_dg.xml") Then
Dim dsdg As New DataSet
dsdg.ReadXml("C:\MyData_dg.xml",
XmlReadMode.DiffGram)
ds.Merge(dsdg)
End If
Dim tbl As DataTable = ds.Tables("Customers")
Dim intIndex As Integer = 0
For Each row As DataRow In tbl.Rows
Console.WriteLine("Row {0} - {1}", intIndex,
row.RowState)
intIndex = intIndex + 1
Next
End Select

When I run the app in "Modify" mode, I see the following on my console:

Row 0 - Unchanged
Row 1 - Modified
Row 2 - Deleted
Row 3 - Added


If I can get the merge function to work the way I want it, then I
should see the same when I run the app in "Review" mode, but instead, I
am seeing this...

Row 0 - Unchanged
Row 1 - Unchanged
Row 2 - Unchanged

Any ideas?

Thanks again for the advice!
 
P

processoriented

Hello Again,

I just got it! Instead of merging the old data with the new, I just
grab the schema from the original and apply the diffgram for the
data...

The new code looks like this:

Case "Review"
ds.ReadXmlSchema("C:\MyData.xml")
ds.AcceptChanges()
If
My.Computer.FileSystem.FileExists("C:\MyData_dg.xml") Then
ds.ReadXml("C:\MyData_dg.xml",
XmlReadMode.DiffGram)
Else
ds.ReadXml("C:\MyData.xml"XmlReadMode.ReadSchema)
ds.AcceptChanges()
End If
Dim tbl As DataTable = ds.Tables("Customers")
Dim intIndex As Integer = 0
For Each row As DataRow In tbl.Rows
Console.WriteLine("Row {0} - {1}", intIndex,
row.RowState)
intIndex = intIndex + 1
Next
End Select

....Then again, I could have gone with SusieDBA's recommendation and
incurred the overhead of adding a database to every user's machine...
 
P

processoriented

Well, sure they do... but my solution only requires ten lines of code.
creating and maintaining databases on every machine seems much more
complex.

look, I don't mean any offence, but I came to this forum with a
question on how to use a function that was clearly designed into
ADO.NET & vb; and your recommendation read like you were telling me
that I was a "jackass" for wanting to use this function, yet the
alternative you offered was more complicated. Back in the ADODB days
I had tried a JET db for a similar function, and it took over a hundred
lines of code to create the database just like I wanted it... maybe
going from ADO.NET to Jet is easier than ADODB to Jet was, maybe its
not, but the experience from the old days made me think that finding a
completely .Net solution that didn't require any of the mucking about
with jet was preferable. Now that I have the functionality that I
wanted, I feel vindicated.
 
S

susiedba

100 lines of code?

I could build amazon.com in 100 lines of code.. ROFL

VB.net and your ADO.net and all that other crap is 100 times more
verbose..
 
R

Ryan S. Thiele

I would use whichever way. Keep in mind the resources.
Remember, slow apps never get used :)

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
Hello Again,

I just got it! Instead of merging the old data with the new, I just
grab the schema from the original and apply the diffgram for the
data...

The new code looks like this:

Case "Review"
ds.ReadXmlSchema("C:\MyData.xml")
ds.AcceptChanges()
If
My.Computer.FileSystem.FileExists("C:\MyData_dg.xml") Then
ds.ReadXml("C:\MyData_dg.xml",
XmlReadMode.DiffGram)
Else
ds.ReadXml("C:\MyData.xml"XmlReadMode.ReadSchema)
ds.AcceptChanges()
End If
Dim tbl As DataTable = ds.Tables("Customers")
Dim intIndex As Integer = 0
For Each row As DataRow In tbl.Rows
Console.WriteLine("Row {0} - {1}", intIndex,
row.RowState)
intIndex = intIndex + 1
Next
End Select

....Then again, I could have gone with SusieDBA's recommendation and
incurred the overhead of adding a database to every user's machine...
 
S

susiedba

a) a database on each users' machine isn't that bad of a deal
- simplifies code
- simplifies sorting

b) VB 2005 supports 'user instances' of SQL Server 2005 databases..
this makes #a plug and play

c) if that's too complex for you then put a database on a SERVER like
where it should be

d) stop bitching about 'overhead'; you're the dipshit that's using XML

-Susie, DBA
 
B

BK

Don't worry about SusieDBA he/she has many aliases (Larry Linson,
Master Programmer, and Aaron.Kempf to name a few) to disguise his/her
frustration. Know that you can get a lot of useful information from
this forum and that you will need to weed through the occasional
childish rant.
 
S

susiedba

it's not a childish RANT

keep your data in a DATABASE and spit on anyone that tells you
otherwise

-Susie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top