DB table in Dataset

  • Thread starter Thread starter al
  • Start date Start date
A

al

Greetings,

Can someone please tell me how the column name is stored in ADO.NET.
I mean I can't find it in the indexing of the rows and items. Do I
need to hardcode the column name????

ds.tables(0).rows(0).item(0) ' this gives me the first col. and row
content

MTIA,
Grawsha
 
The column name is kept in the DataColumn object. Each
table in a DataSet has a collection of DataColumns.

So, the following enumeration will give you the ordinal
position and name of each column in a table.

Dim col as DataColumn
For each col in ds.tables(0).columns
Debug.writeline(col.ordinal.tostring & ": " &
col.columnname)
next

If you need to get the contents of a specific row and
column, the best way I know is to declare a row, like
this:

Dim r as DataRow
r = ds.tables(0).rows(x)

....where x is the row position of the specific row you
need.

Then, given a specific column ordinal (that you might
have obtained from an enumeration such as the one above),
the following will give you the value you need:

r(col.ordinal)

Of course, you can use another integer as well. This
will list all the values in a table:

Dim table as DataTable
Dim row as DataRow, i as integer
For each row in table.rows
For i = 0 to table.columns.count - 1
debug.write (row(i))
Next
Next

You can also use the column name to reference specific
values, like this:

r(col.columnname)

Similarly, you can use any string value, as long as it's
a column name - like this:

r("Col1") ...assuming there's a column called "Col1".

This is because "items" (i.e. a specific column value
within a DataTable row) is the default collection for the
DataRow object. Like most collections, it can be
referenced by a string value (column name) or an integer
(ordinal position).

Hope that helps
 
Back
Top