Home All Groups Group Topic Archive Search About

How can I get the data type of a data table's columns?

Author
8 Oct 2006 2:34 PM
vvenk
Hello:

I created a datatable with two columns:

        ' Add three column objects to the table.
        idColumn = New DataColumn()
        idColumn.DataType = System.Type.GetType("System.String")
        idColumn.ColumnName = "CaseId"
        dtTable.Columns.Add(idColumn)

        idColumn = New DataColumn()
        idColumn.DataType = System.Type.GetType("System.Int64")
        idColumn.ColumnName = "CaseVersion"
        dtTable.Columns.Add(idColumn)

During run-time, I want to get the data type of each column so that I can
cast the data to the right datatype.

But when I investigate using Row(ColumnIndex).GetType.FullName, I alway get
"System.DBNull" irregardless of what column it is.

Can somebody guide me?

Thanks.

Venki

ps: I initially postedt this message under a different discusson group by
mistake. I apologize for double-posting.

Author
8 Oct 2006 2:59 PM
Cor Ligthert [MVP]
VVenk,

System.DBNull tells that there is no value in the item, it is not the
column.

Cor

Show quoteHide quote
"vvenk" <vv***@discussions.microsoft.com> schreef in bericht
news:975EB1E2-84EE-4680-817C-E974BDFD47A6@microsoft.com...
> Hello:
>
> I created a datatable with two columns:
>
>        ' Add three column objects to the table.
>        idColumn = New DataColumn()
>        idColumn.DataType = System.Type.GetType("System.String")
>        idColumn.ColumnName = "CaseId"
>        dtTable.Columns.Add(idColumn)
>
>        idColumn = New DataColumn()
>        idColumn.DataType = System.Type.GetType("System.Int64")
>        idColumn.ColumnName = "CaseVersion"
>        dtTable.Columns.Add(idColumn)
>
> During run-time, I want to get the data type of each column so that I can
> cast the data to the right datatype.
>
> But when I investigate using Row(ColumnIndex).GetType.FullName, I alway
> get
> "System.DBNull" irregardless of what column it is.
>
> Can somebody guide me?
>
> Thanks.
>
> Venki
>
> ps: I initially postedt this message under a different discusson group by
> mistake. I apologize for double-posting.
Author
8 Oct 2006 6:17 PM
vvenk
Cor:

So, how can find out what the data type is?

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> VVenk,
>
> System.DBNull tells that there is no value in the item, it is not the
> column.
>
> Cor
>
> "vvenk" <vv***@discussions.microsoft.com> schreef in bericht
> news:975EB1E2-84EE-4680-817C-E974BDFD47A6@microsoft.com...
> > Hello:
> >
> > I created a datatable with two columns:
> >
> >        ' Add three column objects to the table.
> >        idColumn = New DataColumn()
> >        idColumn.DataType = System.Type.GetType("System.String")
> >        idColumn.ColumnName = "CaseId"
> >        dtTable.Columns.Add(idColumn)
> >
> >        idColumn = New DataColumn()
> >        idColumn.DataType = System.Type.GetType("System.Int64")
> >        idColumn.ColumnName = "CaseVersion"
> >        dtTable.Columns.Add(idColumn)
> >
> > During run-time, I want to get the data type of each column so that I can
> > cast the data to the right datatype.
> >
> > But when I investigate using Row(ColumnIndex).GetType.FullName, I alway
> > get
> > "System.DBNull" irregardless of what column it is.
> >
> > Can somebody guide me?
> >
> > Thanks.
> >
> > Venki
> >
> > ps: I initially postedt this message under a different discusson group by
> > mistake. I apologize for double-posting.
>
>
>
Author
8 Oct 2006 7:07 PM
Oenone
vvenk wrote:
> So, how can find out what the data type is?

Use the dtTable.Columns(index).DataType property.

HTH,

--

(O)enone