Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:29:59+00:00 2026-06-01T21:29:59+00:00

Is it possible to create a new DataRow object and add columns to it

  • 0

Is it possible to create a new DataRow object and add columns to it at runtime?

// How can I specify column names for this data row object?
DataRow row = new DataRow();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:29:59+00:00Added an answer on June 1, 2026 at 9:29 pm

    I don’t think you can add columns to a datarow, but you certainly can to a datatable. Here’s some code to do this for VB:

    Enum enumType
        StringType = 1
        BooleanType = 2
        DateTimeType = 3
        DecimalType = 4
        DoubleType = 5
        IntegerType = 6
        CharType = 7
    End Enum
    
    Private Shared ReadOnly Property ColumnDataType(ByVal ThisDataType As enumType) As String
        Get
    
            'DataType values supported are:
            'System.Byte, System.Char, System.DateTime, System.Decimal, System.Double, System.Int16, System.Int32, System.Int64, 
            'System.SByte, System.Single 
    
            Select Case ThisDataType
                Case enumType.BooleanType
                    Return "System.Boolean"
                Case enumType.DateTimeType
                    Return "System.DateTime"
                Case enumType.DecimalType
                    Return "System.Decimal"
                Case enumType.DoubleType
                    Return "System.Double"
                Case enumType.IntegerType
                    Return "System.Int32"
                Case enumType.StringType
                    Return "System.String"
                Case enumType.CharType
                    Return "System.Char"
                Case Else
                    cnst.ErrorDisplay("No such data type as " & ThisDataType.ToString)
                    Return Nothing
            End Select
    
        End Get
    End Property
    Public Shared Sub AddColumn(ByRef dt As DataTable, ByVal ColumnName As String, ByVal ThisDataType As enumType)
    
        Dim dc As DataColumn = New DataColumn(ColumnName)
        dc.DataType = System.Type.GetType(ColumnDataType(ThisDataType))
        dt.Columns.Add(dc)
    
    End Sub
    

    The code uses an enumeration. I got some of the ideas from this page. The idea is that you can call the AddColumn method to add any column that you like to the datatable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible to create new {variable = x.something} and specify variable name dynamically?
Possible Duplicate: Create new C++ object at specific memory address? I am writing what
Is it possible to create a new Location object in javascript? I have a
I thought it was possible to create a new model object through an association.
I can create new contact with Intent by passing info as extra data with
Is possible create (register) a new class in runtime using delphi. I have a
Is it possible to create a new properties file and add keys and values
Is it possible to create a new Date() object to get the current date,
I am using Excel VBA 2003. Is it possible to create new recordset by
I'm using Umbraco 5. Is it possible to create new Document Type programmatically using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.