• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 979
  • Last Modified:

Datatable add int column to extisting table

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
johnkainn
Asked:
johnkainn
  • 2
2 Solutions
 
LordOfPortsCommented:
Try System.Int32 instead of System.Int, i.e.:

ds.Tables[0].Columns.Add("NewId", System.Type.GetType("System.Int32"));
0
 
Mihai StancescuSoftware Engineer Commented:
You can try this:

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


Hope this helps!

Regards,
Mishu
0
 
icenhanceCommented:
thanks
0
 
Mihai StancescuSoftware Engineer Commented:
Your welcome !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now