Column 'ColumnName' does not belong to table Table.

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
I have created some code that runs as expected. I am now trying to retrieve a value from one column using this code:

VB.NET:
ds.Tables(0).Rows(0).Item("ColumnName").Value
- Also have tried .ToString

This produces the error "Column 'ColumnName' does not belong to table 'Table'. So i changed the code to

VB.NET:
ds.Tables("TableName").Rows(0).Item("ColumnName").Value

This produces the error

Object reference not set to an instance of an object.

Im lost where the problem is and why....Could anyone advise?

Thanks
 
I resolved this by using the code

VB.NET:
ds.Tables(0).Rows(0).Item(0).ToString

So why has this worked and not by using the name of the column/tables?
 
You're supposed to be passing the actual names of the tables and columns, not the literal strings "TableName" and "ColumnName". What you're doing is like calling out "Could PersonName please come here" and expecting some to actually respond. You have to call the person's name, not "PersonName".
 

Latest posts

Back
Top