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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vvenk

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

    Hello:

    I created a datatable with two columns:

    ' Add three column objects to the table.
    idColumn = New DataColumn()
    idColumn.DataTy pe = System.Type.Get Type("System.St ring")
    idColumn.Column Name = "CaseId"
    dtTable.Columns .Add(idColumn)

    idColumn = New DataColumn()
    idColumn.DataTy pe = System.Type.Get Type("System.In t64")
    idColumn.Column Name = "CaseVersio n"
    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.FullN ame, I alway get
    "System.DBN ull" 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.
  • Cor Ligthert [MVP]

    #2
    Re: How can I get the data type of a data table's columns?

    VVenk,

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

    Cor

    "vvenk" <vvenk@discussi ons.microsoft.c omschreef in bericht
    news:975EB1E2-84EE-4680-817C-E974BDFD47A6@mi crosoft.com...
    Hello:
    >
    I created a datatable with two columns:
    >
    ' Add three column objects to the table.
    idColumn = New DataColumn()
    idColumn.DataTy pe = System.Type.Get Type("System.St ring")
    idColumn.Column Name = "CaseId"
    dtTable.Columns .Add(idColumn)
    >
    idColumn = New DataColumn()
    idColumn.DataTy pe = System.Type.Get Type("System.In t64")
    idColumn.Column Name = "CaseVersio n"
    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.FullN ame, I alway
    get
    "System.DBN ull" 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.

    Comment

    • vvenk

      #3
      Re: How can I get the data type of a data table's columns?

      Cor:

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

      "Cor Ligthert [MVP]" wrote:
      VVenk,
      >
      System.DBNull tells that there is no value in the item, it is not the
      column.
      >
      Cor
      >
      "vvenk" <vvenk@discussi ons.microsoft.c omschreef in bericht
      news:975EB1E2-84EE-4680-817C-E974BDFD47A6@mi crosoft.com...
      Hello:

      I created a datatable with two columns:

      ' Add three column objects to the table.
      idColumn = New DataColumn()
      idColumn.DataTy pe = System.Type.Get Type("System.St ring")
      idColumn.Column Name = "CaseId"
      dtTable.Columns .Add(idColumn)

      idColumn = New DataColumn()
      idColumn.DataTy pe = System.Type.Get Type("System.In t64")
      idColumn.Column Name = "CaseVersio n"
      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.FullN ame, I alway
      get
      "System.DBN ull" 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.
      >
      >
      >

      Comment

      • Oenone

        #4
        Re: How can I get the data type of a data table's columns?

        vvenk wrote:
        So, how can find out what the data type is?
        Use the dtTable.Columns (index).DataTyp e property.

        HTH,

        --

        (O)enone


        Comment

        Working...