473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Inserting a new row into a dataset table

If I have this as my XML file

<?xml version="1.0" standalone="yes" ?>
- <opml>
- <body>
- <outline text="RssImporter OPML">
<outline title="CNN" htmlUrl=""
xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" />
</outline>
</body>
</opml>

And I use this code to add a new row

System.Data.DataSet myds = new System.Data.DataSet();
myds.ReadXml(@"C:\Program Files\RSSImporter\Data\feeds.xml");
System.Data.DataRow dr;
dr = myds.Tables[2].NewRow();
dr[0] = "test";
myds.Tables[2].Rows.Add(dr);
myds.AcceptChanges();
myds.WriteXml(@"C:\Program Files\RSSImporter\Data\feeds2.xml");

I end up with:

<?xml version="1.0" standalone="yes"?>
<opml>
<body>
<outline text="RssImporter OPML">
<outline title="CNN" htmlUrl=""
xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" />
</outline>
</body>
<outline title="test" />
</opml>

But the new row with the title "test" should go right after the CNN entry
like this:

<?xml version="1.0" standalone="yes"?>
<opml>
<body>
<outline text="RssImporter OPML">
<outline title="CNN" htmlUrl=""
xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" />
<outline title="test" />
</outline>
</body>
</opml>
Any idea on what I could be doing wrong?

Thanks
May 8 '06 #1
1 1747
Hello Cooper,

Because this is behavior of DataTable. What are you going to do is to apply
your own XML structure to the DataTable XML format.
It's not good idea, because DataTable Xml structure don't guarantee required
behavior in your case and could be changed any time.

What do you really need is use XSLT to transform your data from the dataTable
XML to your OMPL format (btw using DataTable is not necessary, u even could
use DataReader but more work required for transformation)

C> If I have this as my XML file
C>
C> <?xml version="1.0" standalone="yes" ?>
C> - <opml>
C> - <body>
C> - <outline text="RssImporter OPML">
C> <outline title="CNN" htmlUrl=""
C> xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" />
C> </outline>
C> </body>
C> </opml>
C> And I use this code to add a new row
C>
C> System.Data.DataSet myds = new System.Data.DataSet();
C> myds.ReadXml(@"C:\Program Files\RSSImporter\Data\feeds.xml");
C> System.Data.DataRow dr;
C> dr = myds.Tables[2].NewRow();
C> dr[0] = "test";
C> myds.Tables[2].Rows.Add(dr);
C> myds.AcceptChanges();
C> myds.WriteXml(@"C:\Program Files\RSSImporter\Data\feeds2.xml");
C> I end up with:
C>
C> <?xml version="1.0" standalone="yes"?>
C> <opml>
C> <body>
C> <outline text="RssImporter OPML">
C> <outline title="CNN" htmlUrl=""
C> xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" />
C> </outline>
C> </body>
C> <outline title="test" />
C> </opml>
C> But the new row with the title "test" should go right after the CNN
C> entry like this:
C>
C> <?xml version="1.0" standalone="yes"?>
C> <opml>
C> <body>
C> <outline text="RssImporter OPML">
C> <outline title="CNN" htmlUrl=""
C> xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" />
C> <outline title="test" />
C> </outline>
C> </body>
C> </opml>
C> Any idea on what I could be doing wrong?
C>
C> Thanks
C>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sql_Michael_dotnet | last post by:
Can anyone help me figure out how to insert data into SQL Server when a table to hold the data does not yet exist. I am able to insert data into a existing table in the following fashion. But what...
4
by: Deepankar | last post by:
Hi, I was trying to change an example for SQL Server to work with Access db to insert image data. I have everything working except getting the OleDbParameter type for the image column. The...
0
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
2
by: a | last post by:
NEW Post Here's my best guess at how to insert this dataset.... the code runs, but no new records are added to the sql table. I've read and split a delimited text file into a dataset. It...
2
by: sweetness | last post by:
I'm new to this and desperately need help, I'm trying to insert into an sql db and i have no idea what to do and why. i created an sqladapter, and an sqlconnection by dragging and dropping. this...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
0
by: hzgt9b | last post by:
Using VS2003, VB.NET, Here's some pseudo code that I'm trying to get to work... if <a specific record existsthen do nothing else <insert the specific record> Endif I've got the code...
3
by: joel | last post by:
Hi guys, Im new to vb.net and i have this problem how do i insert another row into my datatable... (i guess it's like creating a for loop or something i really have no idea)... in this code i...
0
by: toyin | last post by:
hello, pls help look through this code its not inserting the record in dataset into the another database. i want to insert the row in the dataset into another table in another database. pls help....
10
by: Newbie | last post by:
howdy... i am trying to execute a statement where i insert a record with datetime values into a sql database. Dim sqlcmd As New SqlCommand sqlcmd.CommandText = "update tbl_event set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.