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 7407805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:47:31+00:00 2026-05-29T05:47:31+00:00

Is it possible to have a DataColumn in a DataTable that contains int and

  • 0

Is it possible to have a DataColumn in a DataTable that contains int and long values? It should return an int value if a valid int else it should return a long value.

For some background why I want to achieve this, I have released a product that creates the DataColumn of type int, but it should have been long from the start. Now I don’t want to break existing projects that explicitly casts the value to int, but I would like to allow long values in the column.

Is there an event I can subscribe to on the DataTable to convert the value to int?

The following code should execute correctly.

        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("IntAndLong", typeof(long));

        DataRow intRow = dataTable.NewRow();
        intRow[0] = 123;
        dataTable.Rows.Add(intRow);

        DataRow longRow = dataTable.NewRow();
        longRow[0] = 3000000000;
        dataTable.Rows.Add(longRow);

        long longValue = (long)dataTable.Rows[1][0];
        int intValue = (int)dataTable.Rows[0][0];
  • 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-05-29T05:47:32+00:00Added an answer on May 29, 2026 at 5:47 am

    I would suggest collecting the datacolumn value in a long type variable, check its value to be less than int.MaxValue and bigger than int.MinValue and then cast it to an int variable if you need it there.

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

Sidebar

Related Questions

Possible Duplicate: Have I misunderstood what heredoc should do? I read that Here document
Is it possible to have a free iPhone app that has say an initial
I have an update statement in SQL server where there are four possible values
Is it possible to build a DataTable object from scratch using F# I have
I have a DataTable that I am attempting to upload, but I run into
Is it possible to have an custom annotation that do the same work as
Is it possible have two projects with the same name in flex builder? Here
is possible to have a separator between elements of a GridView? Thanks
Is it possible to have a many to many relationship between two tables, and
is it possible to have a specific element on top of the list? backgoround:

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.