S
Stephen
OK, I have filled a DataSet with an SqlDataAdapter and I just want the data
in one column of one row. How can I do this since the following gives me
the infamous 'Object reference not set to an instance of an object' error:
strng = datset.Tables("Users").Rows(0).Item("Users").ToString()
My table is called Users and I want the first row, and the only column is
also called Users.
I broke it down by declaring a DataTable and a DataRow etc and the problem
comes up at the Rows stage, I can assign tbl=datset.Tables("Users") with no
problem, but cannot assign
rw=tbl.Rows(0) without getting the error above.
And you can't declare a New DataRow because the New constructor is Private
So can someone please give me example code on how to extract one element
from a DataSet into a variable so it can be used in code. MSDN only gives
examples on how to manipulate data while still in the DataSet or how to bind
it, rarely how to extract it in code.
The one example they do give uses
For Each tbl In datset.Tables
For Each rw In tbl.Rows
For Each col In tbl.Columns
Debug.Print(rw(col))
Next
Next
Next
But I still get the error when I try doing this, in the For Each rw In
tbl.Rows. Somehow I can't get any rows at all.
in one column of one row. How can I do this since the following gives me
the infamous 'Object reference not set to an instance of an object' error:
strng = datset.Tables("Users").Rows(0).Item("Users").ToString()
My table is called Users and I want the first row, and the only column is
also called Users.
I broke it down by declaring a DataTable and a DataRow etc and the problem
comes up at the Rows stage, I can assign tbl=datset.Tables("Users") with no
problem, but cannot assign
rw=tbl.Rows(0) without getting the error above.
And you can't declare a New DataRow because the New constructor is Private
So can someone please give me example code on how to extract one element
from a DataSet into a variable so it can be used in code. MSDN only gives
examples on how to manipulate data while still in the DataSet or how to bind
it, rarely how to extract it in code.
The one example they do give uses
For Each tbl In datset.Tables
For Each rw In tbl.Rows
For Each col In tbl.Columns
Debug.Print(rw(col))
Next
Next
Next
But I still get the error when I try doing this, in the For Each rw In
tbl.Rows. Somehow I can't get any rows at all.