|
-
Apr 8th, 2003, 02:10 PM
#1
Thread Starter
Addicted Member
Adding data: ADO.NET, ASP.NET, and XML
I’m trying to write a web application sort of like mapquest, except for on a much much smaller scale, which will only have 100-150 locations, and, there will not be a search function. More like “Click on this link to find the location”. The first thing I’m trying to do is write a web application that will allow me to add the information I need, which entails submitting information through a form. Since my data is relatively small and static, I thought that it made sense to have the data source for ADO.NET be an XML file instead of a database. Since this information will only need to be added once, and changed infrequently, I envision one person sitting down and entering the information in 1 or 2 sittings.
So my question is, what’s the best way? Do I need to open the xml file, read it into the dataset, add a new location, and rewrite the entire file each time I add a location? It seems like a lot of excess accessing, and not efficient at all. Is it possible to keep adding to the dataset and then write the file all at once? I know there are risks involved with that too, though, like what if the program crashes before the data is written to the XML file. Or am I wrong altogether, and would it just be better to use a database instead?
Thoughts? Ideas? I’ve never written a significant web app before, so I am not sure of all the rules and conventions.
Thanks.
-
Apr 8th, 2003, 08:05 PM
#2
-
Apr 8th, 2003, 11:22 PM
#3
Thread Starter
Addicted Member
OK.
Can you give me specific reasons why it would be better to use a database? I know that's the conventional way it would be done, but my reasoning was since the dataset is small and relatively permanent, it really didn't warrent the overhead of a database. I'm willing to use a database, I just want to understand the reasons behind choosing one over the other.
-
Apr 9th, 2003, 01:35 AM
#4
Sure you can keep adding to the dataset and then write the file at the end. If you do that then you'll need to persist the dataset across page laods thats all. Using xml in a dataset is VERY easy.
VB Code:
'start using the dataset
If Me.ViewState("PersistDS") Is Nothing Then
Dim ds As New Dataset()
ds.ReadXML(ServerMapPath("/mydata.xml"))
Me.ViewState("PersistDS")=ds
End If
'then add to it
Dim ds as Dataset=Me.ViewState("PersistDS")
Dim dr As DataRow=ds.Tables(0).NewRow()
dr("Field1")="Whatever"
dr("Field2")=txtWhatever.Text
ds.Tables(0).Rows.Add(dr)
'then when you are done and want to write back to the xml file
Dim ds as Dataset=Me.ViewState("PersistDS")
ds.WriteXML(ServerMapPath("/mydata.xml"))
Last edited by Edneeis; Apr 9th, 2003 at 01:41 AM.
-
Apr 9th, 2003, 01:43 AM
#5
Some of the PROS and CONS of xml are:
PROS
Very easy
Good for smaller data
XML can be used by other things more easily
CONS
Can be slow with complex data
Not as secure
-
Apr 9th, 2003, 11:23 AM
#6
Thread Starter
Addicted Member
Thanks for your reply, Edneeis.
VB Code:
'then when you are done and want to write back to the xml file
Dim ds as Dataset=Me.ViewState("PersistDS")
ds.WriteXML(ServerMapPath("/mydata.xml"))
Where should I put this? In the page_unload method? Or should I have a button on my page that writes the data to file so I can save the data occassionally? If I put it in the unload method, don't I run the risk of losing the data if the page crashes? Excuse my ignorence, but I just need some guidence about the best way to design this.
Thanks.
-
Apr 9th, 2003, 03:53 PM
#7
I'm not up to par on the unload event, I would have a button so the user can control when to save. Although the unload event 'seems' like it should work fine also.
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
|