473,409 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Adding to Datatable

maylortaylor
72 64KB
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
1 978
maylortaylor
72 64KB
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

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

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
0
by: charliewest | last post by:
Using .Net CF, I have a DataSet which includes four tables. Periodically, i must refresh one table w/ new data from the Sql CE database. I go about this as follows: ds.Tables.RemoveAt(3);...
1
by: J. Babe | last post by:
I was wondering how to add the first 20 rows from one datatable to another datatable without getting the error: This row already belongs to another table
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: ven | last post by:
Hello i have a dynamic datatable in my page. I wanna to write data to textboxes and after click on button "ADD data" i want to refresh datagrid on page... Here is my code : ' Insert page code...
1
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the...
9
by: cc | last post by:
Hi, I having created a simple WebService (in VS 2005) with just one WebMethod as follows : public DataTable GetProducts() { DataTable objDataTable = null; // code for filling up the...
3
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.