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
136
votes
19 answers

How can I turn a DataTable to a CSV?

Could somebody please tell me why the following code is not working. The data is saved into the csv file, however the data is not separated. It all exists within the first cell of each row. StringBuilder sb = new StringBuilder(); foreach…
Darren Young
  • 10,972
  • 36
  • 91
  • 150
135
votes
12 answers

How To Change DataType of a DataColumn in a DataTable?

I have: DataTable Table = new DataTable; SqlConnection = new System.Data.SqlClient.SqlConnection("Data Source=" + ServerName + ";Initial Catalog=" + DatabaseName + ";Integrated Security=SSPI; Connect Timeout=120"); SqlDataAdapter adapter = new…
rofans91
  • 2,970
  • 11
  • 45
  • 60
131
votes
5 answers

Simple way to copy or clone a DataRow?

I'm looking for a simple way to make a clone of a DataRow. Kind of like taking a snapshot of that Row and saving it. The values of original Row are then free to change but we still have another saved copy which doesn't change. Is this the correct…
Paul Matthews
  • 2,164
  • 5
  • 20
  • 29
129
votes
23 answers

How to export DataTable to Excel

How can I export a DataTable to Excel in C#? I am using Windows Forms. The DataTable is associated with a DataGridView control. I have to export records of DataTable to Excel.
user1057221
  • 1,363
  • 3
  • 10
  • 7
126
votes
8 answers

How to check if a column exists in a datatable

I have a datable generated with the content of a csv file. I use other information to map some column of the csv (now in the datatable) to information the user is required to fill. In the best world the mapping would be alway possible. But this is…
Rémi
  • 3,867
  • 5
  • 28
  • 44
118
votes
4 answers

Most common way of writing a HTML table with vertical headers?

Hi all it's been a while since I've asked something, this is something that has been bothering me for a while, the question itself is in the title: What's your preferred way of writing HTML tables that have vertical headers? By vertical header I…
Tristian
  • 3,406
  • 6
  • 29
  • 47
118
votes
6 answers

Read SQL Table into C# DataTable

I've read a lot of posts about inserting a DataTable into a SQL table, but is there an easy way to pull a SQL table into a .NET DataTable?
Will
  • 1,317
  • 3
  • 11
  • 10
117
votes
3 answers

c# datatable insert column at position 0

does anyone know the best way to insert a column in a datatable at position 0?
Grant
  • 11,138
  • 32
  • 94
  • 140
111
votes
14 answers

Simple way to convert datarow array to datatable

I want to convert a DataRow array into DataTable ... What is the simplest way to do this?
Developer404
  • 5,716
  • 16
  • 64
  • 102
110
votes
2 answers

ADO.NET DataRow - check for column existence

How do I check for the existence of a column in a datarow? I'm building datatables to organize some data that I've already pulled back from the database. Depending on the type of data in each row, I need to create a datatable with different…
Tone
  • 2,793
  • 6
  • 29
  • 42
108
votes
7 answers

How to change DataTable columns order

How to change Datatable columns order in c#. Example: am created sql table type order is Qty,Unit,Id but in program DataTable order is Id,Qty,Unit. In code Behind am directly pass DataTable to sql table type so the table order is…
Vyasdev Meledath
  • 8,926
  • 20
  • 48
  • 68
106
votes
5 answers

Check if value exists in dataTable?

I have DataTable with two columns Author and Bookname. I want to check if the given string value Author already exists in the DataTable. Is there some built in method to check it, like for Arrays array.contains?
valterriann
  • 1,271
  • 2
  • 10
  • 14
104
votes
4 answers

How can I pass selected row to commandLink inside dataTable or ui:repeat?

I'm using Primefaces in a JSF 2 application. I have a , and instead of selecting rows, I want the user to be able to directly execute various actions on individual rows. For that, I have several s in the last column. My…
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
102
votes
7 answers

Best way to check if a Data Table has a null value in it

what is the best way to check if a Data Table has a null value in it ? Most of the time in our scenario, one column will have all null values. (This datatable is returned by a 3rd party application - we are trying to put a valiadation before our…
Ananth
  • 10,330
  • 24
  • 82
  • 109
102
votes
18 answers

Convert datatable to JSON in C#

I want to get records from database into a DataTable. Then convert the DataTable into a JSON object. Return the JSON object to my JavaScript function. I use this code by calling: string result =…
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71