XML as Dataset - Update question

E

Elmo Watson

I'm just trying to figure out opening an xml file, adding a row and saving
it, but for some reason it's not working, so I hope you can help me out
here -
The code I've got is:

Dim Myds As New DataSet
Myds.ReadXml(GetSPath())
Myds.AcceptChanges()
Dim NewBook As DataRow

NewBook = Myds.Tables("books").NewRow() '<-------- here's the problem - -
error: Object reference not set to an instance of an object.

NewBook ("Title") = sTitle
NewBook ("Author") = sAuthor
NewBook ("ISBN") = sISBN
Myds.Tables("books").Rows.Add(NewBook )
Myds.WriteXml(GetSPath(), XmlWriteMode.IgnoreSchema)

I'm calling the table 'books' because of the xml file root node:
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
</books>

What am I doing wrong
 
A

Andrej Tozon

Hi Elmo,

include column names in your xml to make books a table:

<?xml version=""1.0"" encoding=""ISO-8859-1""?>
<books>
<title></title>
<author></author>
<isbn></isbn>
</books>

Andrej
 

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

Top