Click here to Skip to main content
15,887,485 members
Everything / DataTable

DataTable

DataTable

Great Reads

by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
by Jovan Popovic(MSFT)
Reordering table rows using drag and drop functionality with jQuery DataTables plug-in in ASP.NET MVC applications
by Massimo Fabiano
I know that "returning DataSets from WebServices is the spawn of Satan" but...
by Proneetkumar Pradeep Ray
JQuery Datatable (Dynamic columns) populate after Ajax JSON response via server side processing - Using EF Raw SQL query

Latest Articles

by DiponRoy
The aim of this helper class is to divide a large IEnumerable into multiple small list.
by DiponRoy
The aim of this helper class is to divide a large datatable into multiple small datatables.
by Stefan Vincent Haug
Helper method to apply sorting from DataTables.js parameters in C#
by WyoMetz
Simple and easy paging of a WPF DataGrid with DataTable and LINQ queries

All Articles

Sort by Updated

DataTable 

23 Aug 2010 by #realJSOP
Well, once you retrieve the data, it resides in a DataTable, correct? So just use LINQ to query the DataTable object.
4 May 2011 by #realJSOP
Would it be possible to simply transfer the table as a binary file using FTP or TCP/IP, and then let the remote machine do all the database work itself?If you want to ensure some kind of recovery system (in the event the transfer is interrupted), you could send smaller files and alt least...
27 Dec 2016 by #realJSOP
Look at this article - CSV File Parser[^] If a line comes back "malformed" you can handle that in the code that calls the parsing engine.
6 Jan 2017 by #realJSOP
Iterate the values in the column with a for loop. As you iterate, put each value into a HashTable collection. HashTables will throw an ArgumentException if the value you're trying to add already exists in the collection, so simply handle the exception by doing whatever it is you need to do when...
30 Jan 2017 by #realJSOP
0) Use a class instead of a struct.1) Use serialization to load/save the xml.
25 Mar 2018 by #realJSOP
First, replace this line: string csv_file_path = @"C:\Sample files\L.csv"; with these lines: string[] files = Directory.GetFiles(@"C:\Sample files", "*.csv", SearchOption.TopDirectoryOnly); foreach(string file in files) { DataTable csvData = GetDataTabletFromCSVFile(csv_file_path); ...
3 Apr 2018 by #realJSOP
Change your stored procedure to replace nulls with reasonable default values.
7 Apr 2018 by #realJSOP
An example of evolving code to fit new demands
28 Mar 2019 by #realJSOP
Google (or in my case, DuckDuckGo) is FULL of links: json to datatable at DuckDuckGo[^]
10 Apr 2019 by #realJSOP
0) Create a model class that represents your error info (all the properties you want to save). 1) Create a class derived from List to hold the objects as they are created. 2) As the files are processed, and errors are encountered, create a new instance of your ErrorObject model,...
17 Jun 2020 by #realJSOP
try this: select max(case when isnumeric(roll_no)=0 then 0 else roll_no end) as max_roll if there's a chance your data will not always have a simple numeric value (in other words: 1 2 3b you probably want to try this SELECT...
7 Feb 2022 by #realJSOP
There's at least one article here n CP that describes some methods for doing this: Different Ways to Pass Data to Partial View[^]
28 Apr 2015 by 01sathish
Hi,I'm calling a Stored Procedure say 'GetUserDetails' which retrieves say 3 rows with 3 columns [3X3] with SqlCommand and this is stored in to a DataSet.Now I wanted to loop through each row from the DataSet and write each row to a separate text file, I mean the final outcome should...
25 Dec 2011 by 07navneet
I wanted to know if we can remove/hide/disable a column/items of a datalist on an event. I was trying to hide a column of my datalist on DropDownList's index change. Please let me know how it will be done, do I have to use dataview or else?
21 Jun 2011 by 2irfanshaikh
How do I change my Database server? Or How do I make a proper Database server? Install Sql server. Attach the App_Data database in Sql Server.Change the connection string in the IIS7 Website's web.config file.
22 Jun 2011 by 2irfanshaikh
Check the link given below:A Fast CSV Reader[^]
5 Jul 2011 by 2irfanshaikh
i think this link [^] will help you
21 Dec 2010 by 3pointer
HiI have a form with one label and few textboxes. These controls have data bindings with DataTable "myTable".After "Add New" button click, the all controls with data are empty. I need to preserve the value of the label. Is that possible ?Here are more details:SelectCommand:SELECT...
8 Nov 2018 by 4d.kh4n
This Solution help fix my problem might help u. for more info check this link: columns.createdCell Using createdCell manipulate the DOM within columnDefs options. For example, var table = $("#datatable").DataTable({ searching:false, data: data, "columnDefs": [ { ...
13 Dec 2012 by 90jeri
HI!i have a data grid view that has as datasource one data table of dataset. when i try to add a new row to datatable sometimes datagridview is not displaying any rows. when it happens, it does it just from the application startup(form shows) i mean that the datagridview does not display...
30 Jun 2012 by _Amy
Hi,Here is a grate article on grouping header:Group GridView Data[^] http://www.csharpaspnetarticles.com/2008/11/merging-gridview-headers-to-have.htmlhttp://redsouljaz.wordpress.com/2009/06/12/create-multiple-row-group-header-in-gridview-asp-net/Follow the above link..You'll find...
1 Aug 2012 by _Amy
Hi,Refer the links below:Articles:How to export GridView to Excel, render cells, add WordArt, and fill a custom template[^]http://www.aspdotnet-suresh.com/2011/12/export-selected-gridview-rows-to-excel.html[^]Similar Discussions:Export Gridview to Excel in asp.net and c#[^]Export...
3 Aug 2012 by _Amy
In this case you can remove the columns by using DataTableCollection.RemoveAt function in front-end or you can limit the number of columns in database itself.I'll suggest you to go through following links:A Practical Guide to .NET DataTables, DataSets and DataGrids - Part 2[^] MSDN :...
25 Sep 2012 by _Amy
Hi,Use this function:public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query){ if (query == null) { throw new ArgumentNullException("query"); } IDbCommand cmd = ctx.GetCommand(query as IQueryable); SqlDataAdapter adapter =...
30 Oct 2012 by _Amy
You need to create a function which will convert an image to byte array. Try this:private byte[] GetByteArray(String strFileName){ System.IO.FileStream fs = new System.IO.FileStream(strFileName, System.IO.FileMode.Open); // initialise the binary reader from file streamobject ...
31 Jul 2014 by _Amy
Try this:var res = dt.AsEnumerable().Select(s => s.Field("VrNo")).Distinct().Select(s => s.Substring(0, 2)); foreach (var r in res) Console.WriteLine(r);--Amy
25 Feb 2014 by _Asif_
I guess Dynamic LINQ is the solution. Check below articles.Dynamic LINQ to join on dynamic columns on DataTable[^]Any way to dynamically choose fields in a LINQ query expression?[^]dynamic linq query to dataset[^]
5 Mar 2014 by _Asif_
Check below url for multiple solutions.How To Change DataType of a DataColumn in a DataTable?[^]One solution could also be to use Typed Data table. Search google for more details
27 Oct 2010 by A.J.Wegierski
int empId = dt.Columns[EMP_ID].Ordinal;...int empId = Convert.ToInt32(dRow[empId]);
27 Nov 2012 by Aadhar Joshi
Creating job in sql server which automates taking backup of all stored procedures and functions in physical drive.
23 Jul 2012 by Aarti Meswania
Imports MicrosoftImports Microsoft.Office.Interopand add reference dll "Microsoft.Office.Interop.Excel"function to export data is given below''' ''' Write Excel file as given file name with given data. ''' ''' full file...
27 May 2013 by Aarti Meswania
See example...create table #temp( field1 nvarchar(146), field2 sysname, field3 nvarchar(64), field4 nvarchar(64),field5 nvarchar(64),field6 nvarchar(64),field7 nvarchar(2126))insert into #temp ( field1 , field2 , field3 , field4 ,field5 ,field6 ,field7 )exec sp_helpconstraint...
15 Aug 2021 by Abdelrahman-Dev
I have a button that is responsible for inserting the values inside the textboxes into a datagridview, and then another button responsible for inserting every row in that datagridview into the access datatable by looping through them and...
16 Aug 2021 by Abdelrahman-Dev
Hi, Thanks for viewing my question. I have a button in my form which is responsible for inserting the values inside the textboxes into a datagridview, I have another button that takes all the rows inside the datagridview and inserts them to my...
25 Aug 2021 by Abdelrahman-Dev
Hello, I have a C# winform application for selling books, And in my selling form I have some textboxes where the user can enter the name of the book, the amount, the price, etc... I have a button for inserting these values into an Access...
4 Aug 2015 by Abdul Ahad Monty
Convert DataTable to List using Generics.
25 Feb 2015 by Abdulnazark
you could use Worksheets("Sheet1").Range("A1").Formula = "=Text(value, ""#,##0.000;(#,##0.000);"")"for value = -200000 will be (200,000) format and for colorandif value
24 Sep 2012 by Abhijit Parab
Call Grid.DataBind() method after Grid.DataSource = DT;I hope this is the thing which is missing in your code
5 Feb 2011 by Abhinav S
Are you looking for something like this[^]?
1 Aug 2011 by Abhinav S
There could be two ways to do this - 1) Handle the conversion at the database level. You can use the Convert method [^]to this in your query.2) Handle it once data comes back to the form. If you want to handle this in your code, you can convert the datetime in the source of the datatable,...
31 Oct 2011 by Abhinav S
Go through -http://www.databasejournal.com/features/msaccess/article.php/3528491/Use-System-Tables-to-Manage-Objects.htm[^]http://www.bluemoosetech.com/microsoft-access-video.php?jid=30[^]
10 Dec 2011 by Abhinav S
You could write an extension method that can be called on the datatable and does the calculations.You don't really need to do calculations on the datatable itself. On the other hand, it might actually be worthwhile to calculate the moving averages at the query level as well.
21 May 2012 by Abhinav S
Try DataSet to Excel File Conversion using ExcelLibrary[^].This discussion[^] might also be of some interest to you.
21 Oct 2016 by Abrar Kazi
Try using the render property of jquery datatable
3 Oct 2011 by Adam Covitch
It is common to configure back-end database tables to contain a column with an auto-generated ID unique to each row. This tip describes how to sync the ID generated by the database back to the application layer.
2 Aug 2012 by AdamsEthan
HiI am trying to add individual records from a sql server database into my wpf datagrid. The Problem i am having is that each time i want to add a new item to the datagrid, the datagrid deletes the previous item and only the new one is displayed.This is the code for my button that adds...
6 Jan 2013 by Aditya Magotra
Hi,Use this piece of code: DataSet ds = new DataSet(); DataTable dt = null; ds.ReadXml("Xml File Path"); if(ds.Tables[0]!=null) { dt=new DataTable(); dt = ds.Tables[0]; }
4 Jan 2012 by adnan safdar
Hi how are you? please send me few information about the development of online shopping system.I am looking to form a system in which my standing will be like middle man/services provider.For example I have a stockist with me in business having medicines range and if any my cutomer need to...
26 Jul 2016 by Afzaal Ahmad Zeeshan
You can access the column from the rows of the DataTable. Just like any data table, you first access the rows and then you access their columns. var table = GetYourDataTable();foreach (var row in table) { var column = row["ColumnName"]; // Use the column}The table would...
10 Mar 2014 by agent_kruger
How to inserted dynamic column value's? Example (in the case of fixed column number)Dt.Columns.Add("Name");Dt.Columns.Add(""Id"");Dt.Rows.Add("Mike",1);Example (in the case of dynamic column number)//Column count are not fixed come according to records inserted in...
31 Jul 2012 by agillanders
There are many solutions from down and dirty to elegantly structured. I have found that establishing good practices has paid huge dividends as projects grow. Also a lot of the grunt work is done for you by the compiler.I highly recommend reading Tutorial 1 for your language of choice at...
29 Oct 2014 by AGM KUMARAN
select a.*,b.team from table_name1 as a,table_name2 as b
15 Mar 2021 by aherceo
public ProductsList() { InitializeComponent(); CreateProductList(); DataTable dt = DataTableProductList(productList); // it is assumed that productList is a public variable of type List ...
26 Oct 2018 by Ahmad Sakr
Hello If you mean this data is in datatable so try this List iListOfTables = new List(); foreach (DataRow DRow in ExistingTable.Rows) { if (!iListOfTables.Contains(DRow("TABLES"))) { iListOfTables.Add(DRow("TABLES")); } } DataTable NewTable = new...
13 Apr 2011 by ahmadnawaz
Hi,I want to add an image to a gridview using a datatable in ASP.Net(C#).How can I do this?I want to code in .cs file not in .aspx file for adding image to the datatable and display it in gridview.Any help will be appreciated.
6 Jun 2013 by Ahmed Bensaid
Hello,Have a look at : Paging Through a Query Result
2 Jun 2013 by Ahmed Noaman
I am writing a program send data to excel by using oledb. I used Update statement like next:OleDbConnection MyConnection = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + GeneralData.excelPath + "';Extended Properties=Excel 8.0;")MyConnection.Open();OleDbCommand...
4 Aug 2018 by ahmed_sa
Problem when selecting data from excel sheet and columns name different give error . so that i need to change my code to accept any alias to columns . example in my code column UnitCode represent 'رقم الاستماره' I need it if he write another name accept without exception as 'الاستماره' my...
19 Aug 2018 by ahmed_sa
Problem error no row at position 4 when compare two datatable and remove similar unitcode . why this error and how to solve it if (dtwrongvaluesFinal.Rows.Count > 0) { for (int j = 0; j
26 Sep 2018 by ahmed_sa
Problem SQL Server Database(2014) Items Table ItemCode(pk) ItemName 001 mouse 002 keyboard 003 Headphone On File Excel sheet 2010 ItemCode ItemName 001 ...
26 Sep 2018 by ahmed_sa
Problem error mismatch count parameter when convert list to datatable my list as below my list output of itemcode as below "1830","950","902","540" How to convert list of string to datatable What I have tried: static List SimilarItems = new List(); Similar =...
8 Jul 2019 by ahmed_sa
I work on windows from app csharp visual studio 2015 I have windows form have datagridview name Grid1 this grid have 5 rows and column name Account No what i need is to loop through five rows and add spaces from left and remove spaces from right and in same time it must be have length 15 ....
3 Jun 2020 by ahmed_sa
I work on c# desktop app I cannot export data to excel sheet with multiple tab meaning multi sheet based on data exist on data table module field I use open XML library Data table data as below : Divide Output Excel File To Multi Tab based...
14 Mar 2011 by Ajay Lanjewar
What is the different between dataset and data table.with suitable examples
5 Oct 2012 by ajithk444
Hi all,I have a dataset which binds data to the Gridview in my page. I have check boxes to it. Whe i click a button in my page i need to bind the selected rows in my gridview into another dataset or into another datatable.pls help how to do it.. i have attached my code with this...pls help...
29 Oct 2012 by ajithk444
hi,i have a dataset which has 4 datatables in it and some records in each datatable.i need to select oly the top one record from these 4 tables and save it in either a datatable or any dataset and display these 4 records in my grid. pls help me how to do it in asp.net using c#.pls help me
2 Mar 2018 by Akhil Jain
i have a Datatable and i am adding data to 3 columns of the datatable by calling the function(which is necessary).it's taking around 15 min to process 7,000 records is there any way to use Multithreading and make it faster ? foreach (DataRow row in dtTaskandBugs.Rows) { ...
25 Mar 2018 by Akhil Jain
Age i want to calculate the median of that column along with other values which are higher or lower than the average value What I have tried: .
25 Mar 2018 by Akhil Jain
I am reading a .csv file and getting and calculating avg now i want print value's which are 10% above the avg value. I am converting my data into Datatable. What I have tried: Static void Main(string[] args) { string csv_file_path = @"C:\Sample files\LP.csv"; DataTable...
5 Feb 2011 by Aksh@169
i want to send ....data set data to the msexcel.....how can i send it. i have made a connection string . how can i do that. help me out in this .....
27 Jun 2023 by Akshay malvankar
I have one datable consist around 25000 record datable look like this Id Name Lname bday 1 abc hdhd 25-02-1991 2 cnd dhdhd 7-05-1995 3 dhdhd ddjd 15-07-1993 4 dhhdd ddddhd 05-09-1999 i am converting above...
19 Jan 2024 by Akshay malvankar
Hi I want to validate datable and if there is an any error in row of data table then i want add Error Msg in Error Column "Excel D: column contain Invalid data". in that row which consist error in row. and if any error occured i want to download...
13 Jul 2011 by Al Moje
Hi, Try this if could help... DataTable x = new DataTable(); IEnumerable dtrow = x.AsEnumerable(); var dt = dtrow.GroupBy(dtl => dtl.Field("TransDate")) .Select(dtg => new dtg { ...
23 Aug 2010 by Al-Farooque Shubho
Using SessionState is the solution.Let us assume that you have a Car object which some basic properties, along with a CarDetail object property, something like as follows:public class Car{ public string Make {get;set;} public string Model {get;set;} //Other basic properties ...
8 May 2013 by al3abby
New to DataBase. I have a sql server database with one datatable connected to my application. I want the rows of this datatable to be sorted randomly each time the application starts. How do I do that?[Edit - further detail from OP]I'm trying to make a quiz. My datatable has four colomns...
28 Apr 2011 by Albin Abel
If you know about Personalization you can very well to store and retrieve user specific informations instead of session. However those objects needs to be serializable. This is an alternate suggestion. If you already know about personalization in .Net i don't need to write more on it :)
28 Jan 2022 by Alex Dunlop
I use jQuery DataTable in my ASP.NET MVC project. One of my databasecolumns gives true/false values. I want to translate its value to a string and changes its color. I tried following code for this column: "columns": [ ...
20 Mar 2018 by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
7 Oct 2011 by Alexander Eirich
Hello,I have a DataSet with a connection to an odbc-server.I have in the dataset a DataTable, who fill the data from SQL-Server in a Datagridview.I will copy selected Rows in the Datagridview with changes in the Rows.I get a ArgumentException if I run :...
30 Jun 2012 by Alok Sharma ji
hi folks,i have a problem with gridview in which data is showing like thistitle headers : person name address city transaction_req other detailsdata: someperson someaddress somecity someprice something.......repeatingnow if the person has come through a group it should show in...
30 Apr 2014 by altaf008bd
Hi, Here is a sample code to do the comparison between 2 datatables:DataRow dr; DataTable result = new DataTable(); result.Columns.Add("Tags", typeof(string)); // dr = result.NewRow(); dr[0] = "a"; result.Rows.Add(dr); // ...
3 Mar 2014 by Amalraj Ramesh
Try this DataView dataview = ft.DefaultView; dataview.Sort = "ColumName"; DataTable dt = dataview .ToTable();
5 Mar 2014 by Amalraj Ramesh
Try thisDataView dataview = yourdatatable.DefaultView;dataview.Sort = "ColumName";DataTable dt = dataview .ToTable();
18 Jun 2011 by ambarishtv
this will help you http://csharpdotnetfreak.blogspot.com/2011/04/gridview-examples-in-aspnet-20-35.html[^]
24 Sep 2011 by amgab
I am currently designing an application (.Net WinForms) that needs to access a database (SQL Server).Using the datasource wizard, Visual Studio automatically creates the dataset, tables and classes for rows:For example if I have the Customers table the wizard will create “CustomersRow”...
20 Oct 2014 by Ami_Modi
I have generated javascript datatable in asp.net. I have brought data using webservice. It is displaying perfectly. I have made the cells editable. But I don't know how to write code for editing. My code is as follows$('#showData').dataTable().makeEditable({ "bDestroy": true, ...
29 Oct 2011 by Amir Mahfoozi
Try to work with ADOXhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms677200%28v=vs.85%29.aspx[^]http://msdn.microsoft.com/en-us/library/windows/desktop/ms676514%28v=vs.85%29.aspx[^]And working with ADOX in csharp :http://support.microsoft.com/kb/317881[^]
20 Dec 2018 by Amit Kumar Mohanty
public DataTable getDiffRecords(DataTable dtDataOne, DataTable dtDataTwo) { DataTable returnTable = new DataTable("returnTable"); using (DataSet ds = new DataSet()) { ds.Tables.AddRange(new DataTable[] { dtDataOne.Copy(),...
3 May 2013 by amitesh1989
i have six datatable aspx.cs code:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data;using System.Data.SqlClient;namespace...
3 May 2013 by amitesh1989
Hi I have a list of string in which i have few name in the same line when i use my code i got all name in the same series what i want is to first user in first row of datagrid and second in second. here is my code:using System;using System.Collections.Generic;using...
7 Nov 2011 by anaidy0u
hi folks,i just wonder how to make the data types with alphanumeric value, that will be used in the database and will be set as the primary key. the usual data type used whenever setting the primary key is in Autonumber, and when used will basically stored numbers accordingly (1 2 3...)....
26 Mar 2012 by Anand Ayyappan
Change the first line of code to$link=mysql_connect("localhost", "admin", "") or die(mysql_error());ThanksAnand Ayyappan
16 Sep 2015 by Andre.Postico
Hi guys, this is my first project, I am a beginner programmer so my C# skills are few for now.What I have to do is create a console application that extracts a single table, from an access database, using a SQL query in app.config, so that it is possible to change the SQL without changing...
20 Sep 2015 by Andre.Postico
Thank you for your answers, i already solved the problem, I just needed to create a foreach inside a foreach and specify the operations inside each foreach loop with some if operators.
27 Oct 2010 by Andrew Rissing
Technically, the best approach here for speed and flexibility is to do the following:public class TestClass{ private const string EMP_ID = "EmpId"; public void MyTestMethod() { //GetData fetches data from the database using a SQL query DataTable dt =...
30 Sep 2011 by André Kraak
Supply your class with a implicit conversion operator for System.String, see Using Conversion Operators[^] for an explanation.
4 Oct 2011 by André Kraak
Use the DataGridViewColumn.ReadOnly Property[^].
21 Apr 2015 by Andy Lanng
Hi,This solution still uses a foreach but at least its a linq one.If you know of any way to convert a List to a DataTable.Rows then you wouldn't need it, but in this version the tables are joined once (well, three time) before the foreach starts: DataTable wdt = new...
21 Aug 2013 by Anh Nguyen Trong
I got the same problem and find out the solution:http://www.c-sharpcorner.com/uploadfile/raj1979/show-data-in-wpf-datagrid-using-dataset-data-template/[^]Please see and hope your problem is solved.Trong Anh
25 Sep 2013 by Anil Avhad [IND]
Hi,Make sure your code is not returning Null Value from this code "vm.Gridfill(vm);".