Solved

Datatable add int column to extisting table

Posted on 2008-06-20
4
964 Views
Last Modified: 2012-05-05
I have got a datatable with several rows. I want to add a column of type int.
If I do following I get an error: 'dataType' argument cannot be null.
Parameter name: dataType

 ds.Tables[0].Columns.Add("NewId", System.Type.GetType("System.Int"));

After I have created the column I will loop through the rows in the table and fill values in the new column. How can I add this new int column?
0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 80 total points
ID: 21833320
Try System.Int32 instead of System.Int, i.e.:

ds.Tables[0].Columns.Add("NewId", System.Type.GetType("System.Int32"));
0
 
LVL 11

Assisted Solution

by:Mihai Stancescu
Mihai Stancescu earned 45 total points
ID: 21833340
You can try this:

ds.Tables[0].Columns.Add("NewId", typeof(int));
ds.Tables[0].AcceptChanges;


Hope this helps!

Regards,
Mishu
0
 

Expert Comment

by:icenhance
ID: 25445374
thanks
0
 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 25446338
Your welcome !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question