xml as database

  • Thread starter Thread starter Matteo Cima
  • Start date Start date
M

Matteo Cima

Hi,
I googled and searched in the newsgroup, but still can't find a way to
follow, can't find any example!
I'd love to use xml as a little database for my c# app, just having 2 tables
and a few records, and I also want to do this as a "proof of concept".
What I want to do is just use select, insert into and update sql statements
on it.
I know I have to use datasets, but I can't start, because the documentation
explains the single functions but not the overview of the exact topic, so I
can't even guess how to start.
Just need a few lines of code.

Let's say i have an xml like

<person>
<name>Matteo</name>
<aka>mdm</aka>
</person>
<person>
<name>John</name>
<aka>jj</aka>
</person>


I'd love to just do a sort of "UPDATE PERSON SET AKA='JJ2' WHERE
NAME='john'"
and "INSERT INTO PERSON VALUES('Elwood', 'eb')"

Is this possible? Am I missing something, or, well, What am I missing?

Thanks for every clue.

--
Matteo Cima,
Senior Developer, Mobile Expert, Project Manager, Lead Analyst,
Dotnet, C# (Csharp) and Compact Framework Expert
Digisoft srl Italy
msn: matteodellamontagna_hotmail_com (you know what to do with those
underscores, don't you?)
 
Matteo,

You aren't going to be able to do this. The reason is that manipulation
of an XML document typically requires a DOM. Also, there is no standard
mapping between SQL and XML either which will allow this kind of lnaguage
construct. Finally, there you would need a query engine which would process
this sort of thing (there is XQuery, but AFAIK, it is only for queries).

I would recommend loading the XML in a data set, and then modifying the
data set, or even modifying the XML through the DOM.

Hope this helps.
 
Hi,
You cannot use SQL statements directly on a dataset.
You have to use the methods provded by ADO.NET to Add/Delete/Update
records in a Dataset.

Regards
Benny
 
Thank you all!
Matteo


Uri Dor said:
Where to start with datasets:
A dataset is basically a collection of tables, which you can access
through the Tables property, so "CREATE TABLE KUKU" is
ds.Tables.Add("Kuku"). You'll need to add columns to its Columns property.

"UPDATE PERSON SET AKA='JJ2' WHERE NAME='john'" becomes something like
foreach(DataRow dr in ds.Tables["PERSON"].Select("NAME='john'")
dr["AKA"]="JJ2";

"INSERT INTO PERSON VALUES('Elwood', 'eb')" becomes something like
DataRow dr = ds.Tables["PERSON"].NewRow();
dr["NAME"]="Elwood";
dr["AKA"]= "eb";
ds.Tables["PERSON"].Rows.Add(dr);

I hope this puts some of the pieces in place, enough to continue through
MSDN.

Uri

Matteo said:
Hi,
I googled and searched in the newsgroup, but still can't find a way to
follow, can't find any example!
I'd love to use xml as a little database for my c# app, just having 2 tables
and a few records, and I also want to do this as a "proof of concept".
What I want to do is just use select, insert into and update sql statements
on it.
I know I have to use datasets, but I can't start, because the documentation
explains the single functions but not the overview of the exact topic, so I
can't even guess how to start.
Just need a few lines of code.

Let's say i have an xml like

<person>
<name>Matteo</name>
<aka>mdm</aka>
</person>
<person>
<name>John</name>
<aka>jj</aka>
</person>


I'd love to just do a sort of "UPDATE PERSON SET AKA='JJ2' WHERE
NAME='john'"
and "INSERT INTO PERSON VALUES('Elwood', 'eb')"

Is this possible? Am I missing something, or, well, What am I missing?

Thanks for every clue.
 
Where to start with datasets:
A dataset is basically a collection of tables, which you can access
through the Tables property, so "CREATE TABLE KUKU" is
ds.Tables.Add("Kuku"). You'll need to add columns to its Columns property.

"UPDATE PERSON SET AKA='JJ2' WHERE NAME='john'" becomes something like
foreach(DataRow dr in ds.Tables["PERSON"].Select("NAME='john'")
dr["AKA"]="JJ2";

"INSERT INTO PERSON VALUES('Elwood', 'eb')" becomes something like
DataRow dr = ds.Tables["PERSON"].NewRow();
dr["NAME"]="Elwood";
dr["AKA"]= "eb";
ds.Tables["PERSON"].Rows.Add(dr);

I hope this puts some of the pieces in place, enough to continue through
MSDN.

Uri
 

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

Back
Top