Solved

Datatable add int column to extisting table

Posted on 2008-06-20
4
954 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

11 Experts available now in Live!

Get 1:1 Help Now