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
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