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
53
votes
4 answers

ReadOnlyException DataTable DataRow "Column X is read only."

I've got a short piece of code that originally created an SqlDataAdapter object over and over. Trying to streamline my calls a little bit, I replaced the SqlDataAdapter with an SqlCommand and moved the SqlConnection outside of the loop. Now,…
user153923
53
votes
8 answers

Convert DataTable to IEnumerable

I am trying to convert a DataTable to an IEnumerable. Where T is a custom type I created. I know I can do it by creating a List but I was thinking if there is a slicker way to do it using IEnumerable. Here is what I have now: private…
mpenrow
  • 5,563
  • 9
  • 30
  • 36
52
votes
10 answers

DataTable already belongs to another DataSet

This error is occuring while adding one datatable from a dataset to another ."DataTable already belongs to another DataSet." dsformulaValues.Tables.Add(m_DataAccess.GetFormulaValues (dv.ToTable.DefaultView.ToTable(False,…
kbvishnu
  • 14,760
  • 19
  • 71
  • 101
51
votes
5 answers

Get a DataTable Columns DataType

DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn(gridColumn1, typeof(bool))); I was expecting the result of the below line to include info about the DataColumns Type (bool): ?dt.Columns[0].GetType()
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
51
votes
8 answers

Returning DataTables in WCF/.NET

I have a WCF service from which I want to return a DataTable. I know that this is often a highly-debated topic, as far as whether or not returning DataTables is a good practice. Let's put that aside for a moment. When I create a DataTable from…
goric
  • 11,491
  • 7
  • 53
  • 69
50
votes
8 answers

Getting a count of rows in a datatable that meet certain criteria

I have a datatable, dtFoo, and would like to get a count of the rows that meet a certain criteria. EDIT: This data is not stored in a database, so using SQL is not an option. In the past, I've used the following two methods to accomplish…
Sesame
  • 3,370
  • 18
  • 50
  • 75
50
votes
16 answers

reading Excel Open XML is ignoring blank cells

I am using the accepted solution here to convert an excel sheet into a datatable. This works fine if I have "perfect" data but if I have a blank cell in the middle of my data it seems to put the wrong data in each column. I think this is because in…
leora
  • 188,729
  • 360
  • 878
  • 1,366
49
votes
6 answers

How to convert DataTable to class Object?

I have already developed an application which returns DataTable everywhere. Now my client wants to convert (use some part using service stack), so I need to return DTO (objects) in my application. I don't want to change my existing stored procedures…
amit patel
  • 2,287
  • 8
  • 31
  • 45
49
votes
10 answers

Datatable to html Table

I have question, that maybe someone here wouldn't mind to help me with. I have lets say 3 datatables, each one of them has the following columns: size, quantity, amount, duration Name of datatables and…
Brad Hazelnut
  • 1,603
  • 5
  • 21
  • 33
49
votes
4 answers

get index of DataTable column with name

I have some code which sets the value of cells in a DataRow by column name i.e. row["ColumnName"] = someValue; I want to also set the value for this row in the column immediately to the right of the one found above. Clearly if I was getting the…
Andy
  • 7,646
  • 8
  • 46
  • 69
47
votes
11 answers

Best way to remove duplicate entries from a data table

What is the best way to remove duplicate entries from a Data Table?
Ananth
  • 10,330
  • 24
  • 82
  • 109
46
votes
6 answers

Inner join of DataTables in C#

Let T1 and T2 are DataTables with following fields T1(CustID, ColX, ColY) T2(CustID, ColZ) I need the joint table TJ (CustID, ColX, ColY, ColZ) How this can be done in C# code in a simple way? Thanks.
Dhanapal
  • 14,239
  • 35
  • 115
  • 142
46
votes
8 answers

Find row in datatable with specific id

I have two columns in a datatable: ID, Calls. How do I find what the value of Calls is where ID = 5? 5 could be anynumber, its just for example. Each row has a unique ID.
RSM
  • 14,540
  • 34
  • 97
  • 144
46
votes
4 answers

DataTable, How to conditionally delete rows

I'm engaged in a C# learning process and it is going well so far. I however just now hit my first "say what?" moment. The DataTable offers random row access to its Rows collection, not only through typical collections behavior, but also through…
Alexandre Bell
  • 3,141
  • 3
  • 30
  • 43
46
votes
2 answers

Replacing a DataReader with a DataTable

I'm adapting some code that someone else wrote and need to return a DataTable for time's sake. I have code like this: using (SqlCommand command = new SqlCommand(query, conn)) { //add parameters and their values using (SqlDataReader dr =…
cdub
  • 24,555
  • 57
  • 174
  • 303