ADO.NET: Updating data

K

Kai Thorsrud

Hi,

I've only got a typical crappy Microsoft book about ADO.NET (MSPRESS
!"(¤#&/()&¤# you for mixing manual written code and suddenly adding
designtime controls and wizards for updating data)

I've got a function that is just for learning purposes the naming convention
is bad and such since it's a mix of my conventions and MS Press conventions.
I work with XML files in a database guy's approach. I've managed to create a
schema for my table and i think i know how to add the data correctly but i
can't manage to update my data back to my DataSet and write the DataSet as
an XMLFile.

Would anyone be so kind to help me out with a updatetable thingie ?

My Code fails on the AcceptChanges which i suppose is because my DataRow
isn't written back to the DataSet but how do i do that ?

Public Function doCreateNewXmlfile()
Dim ds As New DataSet
Dim col As DataColumn
Dim oDataRow As DataRow

'Create the table structure.
With ds.Tables.Add("Routers")
col = .Columns.Add("IPAddr", GetType(String))
col.MaxLength = 15
col = .Columns.Add("HostName", GetType(String))
col.MaxLength = 90
col = .Columns.Add("LogFileName", GetType(String))
col.MaxLength = 30
End With
' Save our schema representing our table structure
Dim oFileStream As New
System.IO.FileStream(Me.setXmlIpTableFileSchemaName, FileMode.Create)
ds.WriteXmlSchema(oFileStream)
oFileStream.Close()
oFileStream = Nothing

' Create some data in our xmldatabase
Dim row As DataRow = ds.Tables("Routers").NewRow
row("IPAddr") = "192.168.1.1"
row("HostName") = "tower"
row("LogFileName") = "tower_Log"

row.AcceptChanges()
oFileStream = New System.IO.FileStream(Me.setXmlIpTableFileName,
FileMode.Create)
ds.WriteXml(oFileStream)
oFileStream.Close()
oFileStream = Nothing
End Function

Thanks a lot
/Kai
 

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