DataRowView - GetProperty() = Null Reference Exception????

  • Thread starter Thread starter conorw
  • Start date Start date
C

conorw

All,

This issue is driving me nuts, someone please help.

When I try to access a property in a simple datarow view I get a null
reference exception.

Below is a very simple sample to recreate this issue.

Dim ptbTmp As New Data.DataTable

'add a column and a row
ptbTmp.Columns.Add("MyCode")
ptbTmp.Rows.Add("testCode")

Dim pvwView As New Data.DataView(ptbTmp)

For Each pobj As Data.DataRowView In pvwView

'i get null ref exception here!!
MsgBox(pobj.GetType.GetProperty("MyCode").GetValue(pobj,
Nothing))

Next
 
I think you are misusing GetType().GetProperty("MyCode") - there is no
property of that name, hence the null.

In C# it would go something like this...

DataTable ptbTmp = new DataTable();

ptbTmp.Columns.Add("MyCode");

ptbTmp.Rows.Add("testCode");



DataView pvwView = new DataView(ptbTmp);



foreach ( DataRowView drv in pvwView) {

MessageBox.Show((drv.Row["MyCode"].ToString()));

}



-Drew
 
Back
Top