Questions tagged [datatable]

The term "datatable" is ambiguous. In .NET, it's a class that represents a table of in-memory data. In component based MVC frameworks like JSF and Wicket, it's an UI component that dynamically renders a HTML table based on a collection. For jQuery DataTables plugin, please use the [datatables] tag, for the data.table R package please use [data.table]. For the Python datatable package, use [py-datatable].

DataTable in .NET

A DataTable is a .NET class that represents one table of in-memory data. Unlike other programming languages and platforms, a .NET DataTable is not a GUI control but rather a representation of a SQL table directly accessible in code and a source of data for other controls.

A DataTable may exist as part of a DataSet, which represents an in-memory relational data store. In that context, they can be connected through instances of the DataRelation class, and constrained by ForeignKeyConstraint or UniqueConstraint instances.

A DataTable has a set of DataColumn instances, which describe its schema. Data is stored in DataRow instances.

A DataTable may be sorted and filtered without changing the data by attaching it to a DataView. The sorted and filtered rows are then accessed as instances of the DataRowView class.


DataTable in JSF

A <h:dataTable> is an UI component which allows you to render a HTML table dynamically based on a given List<Entity>. You can specify columns using <h:column>. Assuming that Entity is a fullworthy javabean with 3 properties id, name and value, here's an example how you can render a dynamically sized HTML table out of it:

<h:dataTable value="#{bean.entities}" var="entity">
    <h:column>#{entity.id}</h:column>
    <h:column>#{entity.name}</h:column>
    <h:column>#{entity.value}</h:column>
</h:column>

DataTable in Wicket

A data table builds on data grid view to introduce toolbars. Toolbars can be used to display sortable column headers, paging information, filter controls, and other information.

Data table also provides its own markup for an html table so the user does not need to provide it himself. This makes it very simple to add a datatable to the markup, however, some flexibility. (from Wicket 1.4.18 Javadoc)

22197 questions
68
votes
10 answers

How to calculate the sum of the datatable column in asp.net?

I have a DataTable which has 5 columns: ID Name Account Number Branch Amount The DataTable contains 5 rows. How can I show the sum of the Amount Column in a Label Control as "Total Amount"?
thevan
  • 10,052
  • 53
  • 137
  • 202
68
votes
5 answers

Insert a new row into DataTable

I have a datatable filled with staff data like.. Staff 1 - Day 1 - Total Staff 1 - Day 2 - Total Staff 1 - Day 3 - Total Staff 2 - Day 1 - Total Staff 2 - Day 2 - Total Staff 2 - Day 3 - Total Staff 2 - Day 4 - Total I want to modify so that the…
william
  • 7,284
  • 19
  • 66
  • 106
66
votes
7 answers

IEnumerable to string delimited with commas?

I have a DataTable that returns IDs ,1 ,2 ,3 ,4 ,5 ,100 ,101 I want to convert this to single string value, i.e: ,1,2,3,4,5,100,101 How can i rewrite the following to get a single string var _values = _tbl.AsEnumerable().Select(x => x);
user160677
  • 4,233
  • 12
  • 42
  • 55
63
votes
8 answers

How to insert a data table into SQL Server database table?

I have imported data from some Excel file and I have saved it into a datatable. Now I'd like to save this information in my SQL Server database. I saw a lot of information on the web but I cannot understand it: Someone said insert line by line…
Asaf Gilad
  • 793
  • 1
  • 10
  • 15
62
votes
7 answers

How to get the row number from a datatable?

I am looping through every row in a datatable: foreach (DataRow row in dt.Rows) {} I would like to get the index of the current row within the dt datatable. for example: int index = dt.Rows[current row number] How do i do this?
JOE SKEET
  • 7,950
  • 14
  • 48
  • 64
62
votes
6 answers

Get Cell Value from a DataTable in C#

Here is a DataTable dt, which has lots of data. I want to get the specific Cell Value from the DataTable, say Cell[i,j]. Where, i -> Rows and j -> Columns. I will iterate i,j's value with two forloops. But I can't figure out how I can call a cell…
Abdur Rahim
  • 3,975
  • 14
  • 44
  • 83
61
votes
8 answers

Datatable select with multiple conditions

I have a datatable with 4 columns A, B, C and D such that a particular combination of values for column A, B and C is unique in the datatable. Objective: To find the value of column D, for a given combination of values for column A, B and C. I guess…
Arnkrishn
  • 29,828
  • 40
  • 114
  • 128
60
votes
3 answers

How to get list of one column values from DataTable?

I have DataTable. DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("id", Type.GetType("System.Int32"))); dt.Columns.Add(new DataColumn("name", Type.GetType("System.String"))); // more columns here I need list of "id" values. Can I do…
Kamil
  • 13,363
  • 24
  • 88
  • 183
59
votes
5 answers

Merge 2 DataTables and store in a new one

If I have 2 DataTables (dtOne and dtTwo) and I want to merge them and put them in another DataTable (dtAll). How can I do this in C#? I tried the Merge statement on the datatable, but this returns void. Does Merge preserve the data? For example,…
Xaisoft
  • 45,655
  • 87
  • 279
  • 432
59
votes
15 answers

Convert DataTable to List

I have an strongly typed DataTable of type MyType, I'd like convert it in a List. How can I do this ? Thanks.
TheBoubou
  • 19,487
  • 54
  • 148
  • 236
58
votes
17 answers

Which direction should the arrows point in a sorted table?

In a sorted table, it's common to have an up or a down arrow indicating the sort style. However, I'm having some trouble determining which direction the arrow should point. In an ASC sort, characters are sorted 1-9A-Za-z. Should the arrow point up…
VirtuosiMedia
  • 52,016
  • 21
  • 93
  • 140
57
votes
8 answers

How do I loop through rows with a data reader in C#?

I know I can use while(dr.Read()){...} but that loops every field on my table, I want to retrieve all the values from the first row, and then second... and so on. Let's say I have a table like…
Slacker616
  • 845
  • 1
  • 11
  • 20
56
votes
6 answers

Adding parameters to IDbCommand

I am creating a small helper function to return a DataTable. I would like to work across all providers that ADO.Net supports, so I thought about making everything use IDbCommand or DbCommand where possible. I have reached a stumbling block with the…
Stuart Blackler
  • 3,732
  • 5
  • 35
  • 60
55
votes
6 answers

How to append one DataTable to another DataTable

I would like to append one DataTable to another DataTable. I see the DataTable class has two methods; "Load(IDataReader)" and "Merge(DataTable)". From the documentation, both appear to 'merge' the incoming data with the existing DataTable if rows…
410
  • 3,170
  • 8
  • 32
  • 36
55
votes
6 answers

OleDB & mixed Excel datatypes : missing data

I have an Excel worksheet I want to read into a datatable - all is well except for one particular column in my Excel sheet. The column, 'ProductID', is a mix of values like ########## and n#########. I tried to let OleDB handle everything by itself…
rlb.usa
  • 14,942
  • 16
  • 80
  • 128