HighTechTalks DotNet Forums  

How do I find the datatype of a datatable?

Dotnet Data Tools microsoft.public.dotnet.datatools


Discuss How do I find the datatype of a datatable? in the Dotnet Data Tools forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
vvenk
 
Posts: n/a

Default How do I find the datatype of a datatable? - 10-08-2006 , 10:27 AM






Hello:

I defined a datatable to have 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)

I would like to get the datatype of the column during run time so that I can
cast the data into the right data type.

If I use Row(columnindex).GetType.FullName, it always returns System.DBNull,
irregardless of the columnindex is.

Can somebody guide me?

Thanks.

venki

Reply With Quote
  #2  
Old   
Miha Markic [MVP C#]
 
Posts: n/a

Default Re: How do I find the datatype of a datatable? - 10-09-2006 , 06:58 AM






Perhaps by checking DataColumn's DataType?
dtTable.Columns(0).DataType

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"vvenk" <vvenk (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hello:

I defined a datatable to have 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)

I would like to get the datatype of the column during run time so that I
can
cast the data into the right data type.

If I use Row(columnindex).GetType.FullName, it always returns
System.DBNull,
irregardless of the columnindex is.

Can somebody guide me?

Thanks.

venki



Reply With Quote
  #3  
Old   
Shyamsundar. V
 
Posts: n/a

Default RE: How do I find the datatype of a datatable? - 12-03-2007 , 12:45 AM



Try this

dtTable.Columns(ColumnIndex).DataType.Name
--
Thanks Shyam


"vvenk" wrote:

Quote:
Hello:

I defined a datatable to have 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)

I would like to get the datatype of the column during run time so that I can
cast the data into the right data type.

If I use Row(columnindex).GetType.FullName, it always returns System.DBNull,
irregardless of the columnindex is.

Can somebody guide me?

Thanks.

venki

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.