By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Adding to Datatable

maylortaylor
P: 72
So I have a datatable name 'Users'. It has a columns assigned to it such as "Username", "Amount", and "Rank". But I want to add to this later in the code. I want to add a column for "OrderCount".

So first half of code table will look like this:

Username | Amount | Rank
jsmith | 30 | 1
jdoe | 30 | 2

and halfway through the code i wish to add to this so it looks like this:

Username | Amount | Rank | OrderCount
jsmith | 30 | 1 | 15
jdoe | 30 | 2 | 20

I'm figuring i'll have to use a for loop to loop through the table and add the OrderCount numbers to the specific row, but i'm not sure about how to add that extra column in and making sure the OrderCount gets added to the correct row.

So, i have this so far. "assignedAmount" will go into the "OrderCount" column
Expand|Select|Wrap|Line Numbers
  1. Dim OrderCol As DataColumn = users.Columns.Add("OrderCount")
  2.  
  3.                                         For a = 0 To users.Rows.Count - 1
  4.                                             assignedAmount = ReturnAssignedAmount(users.Rows(a).Item("Username"))
  5.                                             users.Rows(a).Item("OrderCount")
  6.                                         Next
  7.                                         users.AcceptChanges()
Any help?
Apr 12 '13 #1
Share this Question
Share on Google+
1 Reply


maylortaylor
P: 72
Expand|Select|Wrap|Line Numbers
  1. Dim OrderCol As DataColumn = users.Columns.Add("OrderCount")
  2.  
  3.  For a = 0 To users.Rows.Count - 1
  4. assignedAmount = ReturnAssignedAmount(users.Rows(a).Item("Username"))
  5.                                             users.Rows(a).Item("OrderCount") = assignedAmount
  6. Next
  7.  users.AcceptChanges()
Solved:
Apr 12 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.