TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marco Patritti
NA
2
636
VS C# - Dump XML data into Access db table
Oct 9 2017 4:20 PM
Hello,
I am trying to read data from an XML file and insert it into Access db table.
According to my online research, it is best to dump the XML data into a Dataset and then iterate through this dataset to insert the values in the table. Is this recommended or is there an easier way?
My current code is below. can see the values (DateCreated, DateModified, etc) written to console when I run the code. Somehow if I use MessageBox.Show() instead of Console.WriteLine() to see the value in a pop-up message box it does not show the value. The message box appears empty.
If someone can help me reading those values and inserting them into a new dataset, and then iterate through the dataset to insert into table I would greatly appreciate it.
Code:
using
(XmlTextReader reader =
new
XmlTextReader(
"c:\\XML\\MyTest.xml"
))
{
while
(reader.Read())
{
if
(reader.IsStartElement())
{
switch
(reader.Name)
{
case
"File"
:
Console.WriteLine();
break
;
case
"DateCreated"
:
Console.WriteLine(
"DateCreated: "
+ reader.ReadString());
break
;
case
"DateModified"
:
Console.WriteLine(
"DateModified: "
+ reader.ReadString());
break
;
case
"Extension"
:
Console.WriteLine(
"Extension: "
+ reader.ReadString());
break
;
case
"FullPath"
:
Console.WriteLine(
"FullPath: "
+ reader.ReadString());
break
;
case
"ID"
:
Console.WriteLine(
"ID: "
+ reader.ReadString());
break
;
case
"Name"
:
Console.WriteLine(
"Name: "
+ reader.ReadString());
break
;
case
"Size"
:
Console.WriteLine(
"Size: "
+ reader.ReadString());
break
;
}
}
}
}
This is my XML file:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
Files
TotalFiles
=
"3"
>
<
File
>
<
DateCreated
>
2017-08-18T09:34:51
</
DateCreated
>
<
DateModified
>
2017-08-18T09:34:51
</
DateModified
>
<
Extension
>
pdf
</
Extension
>
<
FullPath
>
Apex Clean Energy Management / Apex Clean Energy / Apex Clean Energy / Land / Lease Sig & Pmt Approvals (KP & MG) / Lease Approval Request Form 081717 v1 - signed.pdf
</
FullPath
>
<
ID
>
3cbd2086-7377-4bf2-8458-371206287876
</
ID
>
<
Name
>
Lease Approval Request Form 081717 v1 - signed.pdf
</
Name
>
<
Size
>
1247062
</
Size
>
</
File
>
<
File
>
<
DateCreated
>
2017-08-18T09:34:38
</
DateCreated
>
<
DateModified
>
2017-08-18T09:34:38
</
DateModified
>
<
Extension
>
pdf
</
Extension
>
<
FullPath
>
Apex Clean Energy Management / Apex Clean Energy / Apex Clean Energy / Land / Lease Sig & Pmt Approvals (KP & MG) / Lease Approval Request Form 080317 v1 - signed.pdf
</
FullPath
>
<
ID
>
fe6a8aa3-aa4f-4587-9220-371206286456
</
ID
>
<
Name
>
Lease Approval Request Form 080317 v1 - signed.pdf
</
Name
>
<
Size
>
1074533
</
Size
>
</
File
>
<
File
>
<
DateCreated
>
2017-08-18T09:34:24
</
DateCreated
>
<
DateModified
>
2017-08-18T09:34:24
</
DateModified
>
<
Extension
>
pdf
</
Extension
>
<
FullPath
>
Apex Clean Energy Management / Apex Clean Energy / Apex Clean Energy / Land / Lease Sig & Pmt Approvals (KP & MG) / Lease Approval Request Form 072717 v1 - signed.pdf
</
FullPath
>
<
ID
>
d3cd9f63-257f-4122-b7c4-371206284987
</
ID
>
<
Name
>
Lease Approval Request Form 072717 v1 - signed.pdf
</
Name
>
<
Size
>
879380
</
Size
>
</
File
>
</
Files
>
Reply
Answers (
1
)
Web api model of Counsumer and Retailer
Export data into pdf in MVC4