Click here to Skip to main content
11,928,754 members (54,082 online)
Click here to Skip to main content
Add your own
alternative version


40 bookmarked

Using .xml files to replace small databases

, 2 Sep 2003
Rate this:
Please Sign up or sign in to vote.
Let an XML file become your local small database.

Sample Image


Many software and projects have many files to save data, like .ini, .cfg, .config... And they use any small database hourly, like .mdb. Now, using XML files can replace these files to save any data, under the .NET framework. There are 4 steps that let us complete this mission :p.

Step 1: Building an XML file.

The XML file's formatting must be familiar to you. Like this:


If you open this XML file in VS.NET, you can see button "Data" in the IDE's left bottom. Click the button, you can see some tables from this XML file. Like this:

Sample screenshot

Step 2: Using a DataSet to read XML file.

Create a WinForm project. Add an OpenFileDialog into the main form. We will use it to open the XML file. Like this:

  DataSet ds=new DataSet();; 

Step 3: Control the DataSet.

In a DataSet instance, we can do some operations like select, add, delete, and update... This is a sample method to search some data:

public DataRow[] searchForm(string tables,string expression) 
  //ds is a DataSet instance. 
  DataTable dt=ds.Tables[tables]; 
  DataRow[] drs=dt.Select(expression); 
  return drs; 

And you can add other methods easily. Like these methods:

//delete some rows from a table.
public bool deleteRows(string tables,string expression)
  bool result=false;
  DataTable dt=ds.Tables[tables];
  DataRow[] drs=dt.Select(expression);
    for(int i=0;i<drs.Length;i++) <DRS[].LENGTH;I++)<>drs[i].Delete();
  return result;

Step 4: Using DataSet to save data.

One statement can finish the work. Like this:

//fileName is a xml file's full name. 

Now see, the XML file can save data and we can use DataSet to operate on the data Smile | :) .


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
Sorry,my english is very poor.My name is ShangYuan Wang,and I am working in China GuangXi nanning city,a technology company named biztig.So
my nickname is biztig,and I have an other nickname that is jam_snake. I learned pascal in GuangXi University first at 5 years ago,but my favorite language is C# now.
The image is a famous star in china,and I am her fans.

You may also be interested in...

Comments and Discussions

Generalhello Pin
samiong727-Jan-09 3:29
membersamiong727-Jan-09 3:29 
GeneralFor Yantarian Pin
avodavtyan23-Oct-07 20:46
memberavodavtyan23-Oct-07 20:46 
GeneralInitial conditions Pin
SPIRANCA1-Dec-06 4:40
memberSPIRANCA1-Dec-06 4:40 
Generalcountrymen MM Pin
vcsharp16-Feb-04 16:25
membervcsharp16-Feb-04 16:25 
GeneralGood ideas must leave something to your own imagination ... Pin
intressant@solhem.se25-Sep-03 9:22
memberintressant@solhem.se25-Sep-03 9:22 
GeneralComment Pin
Anonymously10-Sep-03 17:09
sussAnonymously10-Sep-03 17:09 
GeneralRe: Comment Pin
jam_snake10-Sep-03 17:49
memberjam_snake10-Sep-03 17:49 
GeneralRe: Comment Pin
Anonymously12-Sep-03 16:32
sussAnonymously12-Sep-03 16:32 
jam_snake wrote:
But I want to write a compilation units for question b) for a period of time.

Before doing that, tell us more about the girl whose picture is in your profile Wink | ;)
GeneralRe: Comment Pin
Azel Low3-Oct-03 3:40
memberAzel Low3-Oct-03 3:40 
GeneralRe: Comment Pin
yantarian11-Nov-03 4:31
sussyantarian11-Nov-03 4:31 
GeneralRe: Comment Pin
avodavtyan23-Oct-07 4:33
memberavodavtyan23-Oct-07 4:33 
GeneralRe: Comment Pin
eyoung7029-Aug-04 19:52
membereyoung7029-Aug-04 19:52 
GeneralThe other methods Pin
jam_snake10-Sep-03 16:32
memberjam_snake10-Sep-03 16:32 
GeneralRe: The other methods Pin
yantarian11-Nov-03 4:35
sussyantarian11-Nov-03 4:35 
GeneralRe: The other methods Pin
avodavtyan23-Oct-07 5:01
memberavodavtyan23-Oct-07 5:01 
GeneralSome more Pin
lee_connell10-Sep-03 15:40
memberlee_connell10-Sep-03 15:40 
Questionxml as database -max size? Pin
deodatus10-Sep-03 15:25
memberdeodatus10-Sep-03 15:25 
AnswerRe: xml as database -max size? Pin
saturn_one2-Dec-04 11:44
membersaturn_one2-Dec-04 11:44 
AnswerRe: xml as database -max size? Pin
The Man from U.N.C.L.E.25-Jun-07 12:34
memberThe Man from U.N.C.L.E.25-Jun-07 12:34 
GeneralNot enough Pin
dog_spawn4-Sep-03 14:08
memberdog_spawn4-Sep-03 14:08 
GeneralRe: Not enough Pin
lee_connell10-Sep-03 15:37
memberlee_connell10-Sep-03 15:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 3 Sep 2003
Article Copyright 2003 by biztig
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid