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
1140
votes
22 answers

LINQ query on a DataTable

I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in myDataTable where results.Field("RowNo") == 1 select…
Calanus
  • 25,619
  • 25
  • 85
  • 120
310
votes
28 answers

Convert generic List/Enumerable to DataTable?

I have few methods that returns different Generic Lists. Exists in .net any class static method or whatever to convert any list into a datatable? The only thing that i can imagine is use Reflection to do this. IF i have this: List
Josema
  • 4,638
  • 6
  • 22
  • 15
249
votes
14 answers

How do I create a DataTable, then add rows to it?

I've tried creating a DataTable and adding rows to it like this: DataTable dt = new DataTable(); dt.clear(); dt.Columns.Add("Name"); dt.Columns.Add("Marks"); How do I see the structure of DataTable? Now I want to add ravi for Name and 500 for…
Cute
  • 13,643
  • 36
  • 96
  • 112
216
votes
12 answers

Should I Dispose() DataSet and DataTable?

DataSet and DataTable both implement IDisposable, so, by conventional best practices, I should call their Dispose() methods. However, from what I've read so far, DataSet and DataTable don't actually have any unmanaged resources, so Dispose() doesn't…
mbeckish
  • 10,485
  • 5
  • 30
  • 55
205
votes
29 answers

How do you convert a DataTable into a generic list?

Currently, I'm using: DataTable dt = CreateDataTableInSomeWay(); List list = new List(); foreach (DataRow dr in dt.Rows) { list.Add(dr); } Is there a better/magic way?
Iain Holder
  • 14,172
  • 10
  • 66
  • 86
204
votes
23 answers

How to read a CSV file into a .NET Datatable

How can I load a CSV file into a System.Data.DataTable, creating the datatable based on the CSV file? Does the regular ADO.net functionality allow this?
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
193
votes
15 answers

Copy rows from one Datatable to another DataTable?

How can I copy specific rows from DataTable to another Datable in c#? There will be more than one row.
kartal
  • 17,436
  • 34
  • 100
  • 145
189
votes
18 answers

How to select distinct rows in a datatable and store into an array

I have a dataset objds. objds contains a table named Table1. Table1 contains column named ProcessName. This ProcessName contains repeated names.So i want to select only distinct names.Is this possible. intUniqId[i] =…
Ahmed Atia
  • 17,848
  • 25
  • 91
  • 133
170
votes
14 answers

Sorting rows in a data table

We have two columns in a DataTable, like so: COL1 COL2 Abc 5 Def 8 Ghi 3 We're trying to sort this datatable based on COL2 in decreasing order. COL1 COL2 ghi 8 abc 4 def 3 jkl …
vidya sagar
  • 2,001
  • 3
  • 18
  • 18
169
votes
15 answers

DataTable: Hide the Show Entries dropdown but keep the Search box

Is it possible to hide the Show Entries dropdown but keep the Search box in DataTable? I want to always display 10 rows with pagination at the bottom along with search box but do not want to display the Show entries dropdown.
FaisalKhan
  • 2,406
  • 3
  • 25
  • 32
153
votes
9 answers

Check for changes to an SQL Server table?

How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is .NET and C#. I'd like to be able to support any SQL Server 2000 SP4…
TimM
  • 1,885
  • 2
  • 14
  • 12
148
votes
21 answers

Can't bind to 'dataSource' since it isn't a known property of 'table'

I am new in angular 5 development. I am trying to develop a data table with angular material using the example provided here: "https://material.angular.io/components/table/examples". I am getting an error saying Can't bind to 'dataSource' since it…
Rahul Munjal
  • 2,551
  • 2
  • 15
  • 35
142
votes
7 answers

Datatable vs Dataset

I currently use a DataTable to get results from a database which I can use in my code. However, many example on the web show using a DataSet instead and accessing the table(s) through the collections method. Is there any advantage, performance wise…
GateKiller
  • 74,180
  • 73
  • 171
  • 204
139
votes
4 answers

Get all column names of a DataTable into string array using (LINQ/Predicate)

I know we can easily do this by a simple loop, but I want to persue this LINQ/Predicate? string[] columnNames = dt.Columns.? or string[] columnNames = from DataColumn dc in dt.Columns select dc.name;
Lalit
  • 4,897
  • 7
  • 32
  • 36
136
votes
7 answers

How to change the DataTable Column Name?

I have one DataTable which has four columns such as StudentID CourseID SubjectCode Marks ------------ ---------- ------------- -------- 1 100 MT400 …
thevan
  • 10,052
  • 53
  • 137
  • 202
1
2 3
99 100