Problem with NewRow in .NET 2.0

G

Guest

I am trying to add new rows to a DataTable in .NET 2.0 using the code below.
The problem I have is that all new rows have all of the column values set to
System.DBNull.Value instead of the values I assign.

This code works fine in .NET 1.1. I have just migrated the code to .NET 2.0
and this issue has appeared.

If I change the code a bit an use a string array instead of .NewRow(),
everything works as expected.

What is wrong with NewRow?

Function getRoles
Dim dsRole As New DataSet
dsRole.Tables.Add("ROLE")
With dsRole.Tables("ROLE")
.Columns.Add("Role", System.Type.GetType("System.String"), "")
.Columns.Add("Name", System.Type.GetType("System.String"), "")
.Columns.Add("Description",
System.Type.GetType("System.String"), "")
.Columns.Add("Context", System.Type.GetType("System.String"), "")
Dim oRow = .NewRow()
oRow("Role") = "CCB"
oRow("Name") = "Change Control Board"
oRow("Description") = "Person(s) who approve a request"
oRow("Context") = "ORGANIZATION"
.Rows.Add(oRow)
oRow = .NewRow()
oRow("Role") = "SA"
oRow("Name") = "System Administrator"
oRow("Description") = "Manages the technical aspects of the
request system"
oRow("Context") = "GLOBAL"
.Rows.Add(oRow)
End With
getRoles = dsRole.Tables(0)
End Function
 
G

Guest

Never mind I posted too soon... I just found the problem.

I need to declare oRow first.

Dim oRow = .NewRow() is not valid.

I needed

Dim oRow as DataRow
oRow = .NewRow()

Thanks anyway
 

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