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)

20308 questions
1073
votes
23 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
  • 23,416
  • 24
  • 77
  • 118
282
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,248
  • 6
  • 20
  • 15
218
votes
13 answers

How to create a DataTable in C# and how to add rows?

How do create a DataTable in C#? I did 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 Marks. How can I…
Cute
  • 12,313
  • 34
  • 91
  • 111
204
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,108
  • 5
  • 27
  • 47
192
votes
27 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
  • 13,731
  • 10
  • 61
  • 84
183
votes
22 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
  • 41,852
  • 68
  • 257
  • 338
177
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,223
  • 24
  • 88
  • 129
172
votes
13 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
  • 14,786
  • 31
  • 93
  • 141
165
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
  • 1,931
  • 3
  • 16
  • 17
147
votes
8 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,825
  • 2
  • 14
  • 12
144
votes
14 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,026
  • 3
  • 20
  • 32
135
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
  • 68,419
  • 71
  • 167
  • 203
126
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,760
  • 11
  • 41
  • 60
126
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
  • 9,298
  • 52
  • 128
  • 193
122
votes
4 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,016
  • 5
  • 20
  • 28
1
2 3
99 100