Solved

Datatable add int column to extisting table

Posted on 2008-06-20
4
948 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
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 80 total points
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0
 
LVL 11

Expert Comment

by:Mihai Stancescu
Comment Utility
Your welcome !
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now