Results 1 to 7 of 7

Thread: Adding data: ADO.NET, ASP.NET, and XML

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235

    Question 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.

  2. #2
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Umm why use an xml file to store data? Seems like a database would be the way to go
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    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.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'start using the dataset
    2. If Me.ViewState("PersistDS") Is Nothing Then
    3.    Dim ds As New Dataset()
    4.    ds.ReadXML(ServerMapPath("/mydata.xml"))
    5.    Me.ViewState("PersistDS")=ds
    6. End If
    7.  
    8. 'then add to it
    9. Dim ds as Dataset=Me.ViewState("PersistDS")
    10. Dim dr As DataRow=ds.Tables(0).NewRow()
    11. dr("Field1")="Whatever"
    12. dr("Field2")=txtWhatever.Text
    13. ds.Tables(0).Rows.Add(dr)
    14.  
    15. 'then when you are done and want to write back to the xml file
    16. Dim ds as Dataset=Me.ViewState("PersistDS")
    17. ds.WriteXML(ServerMapPath("/mydata.xml"))
    Last edited by Edneeis; Apr 9th, 2003 at 01:41 AM.

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

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    Thanks for your reply, Edneeis.
    VB Code:
    1. 'then when you are done and want to write back to the xml file
    2. Dim ds as Dataset=Me.ViewState("PersistDS")
    3. 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.

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



Click Here to Expand Forum to Full Width