Results 1 to 2 of 2

Thread: Access database to XML database

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Access database to XML database

    Hi,

    In my application I have been using an Access database (mdb files, 2003 format I think). All the data accessing is done completely manually, using code such as this:
    vb.net Code:
    1. Public Sub ExecuteNonQuery(ByVal sql As String, Optional ByVal params As Parameters = Nothing)
    2.         If Me.IsConnected Then
    3.             Using cmd As New OleDbCommand
    4.                 cmd.Connection = Me.Connection
    5.                 cmd.CommandType = CommandType.Text
    6.                 cmd.CommandText = sql
    7.                 cmd.Parameters.Clear()
    8.                 If params IsNot Nothing Then
    9.                     For Each key As String In params.Keys
    10.                         cmd.Parameters.AddWithValue(key, params.Item(key))
    11.                     Next
    12.                 End If
    13.  
    14.                 cmd.ExecuteNonQuery()
    15.             End Using
    16.         Else
    17.             Throw New Exception(strNO_DB_CONNECTION)
    18.         End If
    19.     End Sub

    Basically, I made a class Database, with these methods (also ExecuteScalar, ExecuteReader, Connect, Disconnect, etc). Then I make a Manager class for every table and an Entity class representing one entry in the database. The Entity class is basically just a list of properties corresponding to the fields in the table, while the Manager class loads and saves Entity classes like this:
    vb.net Code:
    1. Public Function Load(ByVal sql As String, Optional ByVal params As Parameters = Nothing) As clsWorkflowItemCollection
    2.             Dim result As New clsWorkflowItemCollection()
    3.  
    4.             Me.Database.Connect()
    5.             Using reader = Me.Database.ExecuteReader(sql, params)
    6.                 While reader.Read()
    7.                     ' The FromReader method sets the properties of a WorkflowListItem instance to the values in the data reader
    8.                     result.Add(clsWorkflowListItem.FromReader(reader))
    9.                 End While
    10.             End Using
    11.             Me.Database.Disconnect()
    12.  
    13.             Return result
    14.         End Function

    What I'm trying to say basically is that I'm not using any of the built in data access things. I never have and I feel no need for them, this works just fine for me and I like the amount of control I have over it.



    Anyway, I would now like to start using XML files instead of an Access database. I am wondering how hard it would be to convert my code to use XML instead of a database. I searched around but all I can find is code that does use the VS built in data access things (sorry not really sure what it's called lol).

    What would I need to change? For example, I'm now using an OleDbConnection object. I'm sure that won't work for XML files, will it? Is there some kind of alternative for XML files (XmlDbConnection? )


    Basically I want to know how much trouble it would be. If it means a WHOLE lot of work to change everything, I'm not doing it. I'd rather use XML files but it's not absolutely required.

    Thanks!

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Access database to XML database

    I heven't done anything with XML, and am just starting to learn LINQ, but it may work for you.
    http://dotnetslackers.com/articles/x...sing-Linq.aspx
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

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