Click here to Skip to main content
15,887,435 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 Title

DataTable 

22 Jun 2022 by nyt1972
Hello, I have an issue that if I use DataTables Ajax render function for a conditional column it duplicates each row in table. If I remove the below line then it works fine, but after adding this every row is displayed twice. { ...
12 May 2014 by AR547
Scenario:I have 4 different dropdownlists for different purposes.1st to get the Employee names and email addresses."DATATEXTFIELD = Detail(emp_code, Empnames) and DATAVALUEFIELD = email"2nd to get the Employee authority names."DATATEXTFIELD = Empnames and DATAVALUEFIELD =...
17 Sep 2013 by CodeBlack
You can create one method for dropdownlist binding and one method which gets data for dropdownlist as mentioned below : protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.BindData(); } ...
12 May 2014 by AR547
Solve this issue regarding dropdownlist and gridview. The scenario is as following: I have one dropdownlist and one gridview. Data from database is binding to dropdownlist. now dropdownlist has 1000+ employee names in DataTextField and employee emails in DataValueField. there is an ADD button...
17 Sep 2013 by Harshil_Raval
Hi,Try this.protected void addemp_Click(object sender, EventArgs e){ DataTable empemails = new DataTable(); int srno = 1; empemails.Columns.Add("Sr.No"); empemails.Columns.Add("EmpName"); empemails.Columns.Add("Email"); foreach...
21 Apr 2011 by TeddyB777
I am using MS VS2008 building in C# and rather green since most of my programming was done in C++. I'm currently using an FTP component to download a csv of names,phone numbers,device type, status, ect and then parse it into a table using the OLEdb adapter. What becomes my issue is that the...
21 Apr 2011 by Nish Nishant
In your OLEDB connection string add HDR=YES.
9 Mar 2011 by RadethDart
Alright, I am having the hardest time figuring this out. I have done research on fixing this for a couple days and I am stuck. It is time to ask for help.In my project I am trying to delete a row out of the database and I read how to do that from many different sources telling me to use Ole...
10 Mar 2011 by Dave Kreskowiak
I suggest reading the documentation on AcceptChanges and Update. Update writes the dirty records in the DataSet/DataTable back to the database. AcceptChanges tells the DataSet/DataTable that the changes that were made are now the current state of the records. The two operations are completely...
19 Aug 2011 by Herman<T>.Instance
Hello Friends,I have the next problem.I have a project (DBConnecting.DataObjects.DataObjects) that is the communication between my windows form app and my Sql Server 2008 Database.In my 2nd project: a Windows form (that references DBConnecting.DataObjects.DataObjects) that calls the...
19 Aug 2011 by Shameel
This[^] article contains information on how to pass information back using IAsyncResult.Create the DataTableEventArgs in your source projectpublic class DataTableEventArgs : System.EventArgs { DataTable dataTable; public DataTable DataTableInfo { get { ...
27 Apr 2015 by Jörgen Andersson
A high performance extension for creating a DataTable from a Generic collection.
18 Jan 2014 by Petr Ivankov
Application of abstract approach to database domain
16 Jun 2011 by Rajiv nayan
I SOLVED THIS FROM GIVEN CODE 'Str1 value come from database like.. 1 Month 0r 2 Year Str1 = MyDr(1).ToString Dim rep As String = String.Empty Dim rep2 As String = String.Empty For i As Integer = 0 To...
11 Jul 2013 by deva936
forgive me if it is a very silly questioni access Cell of DataTable like thisstring value=dataTable.rows[0]["DataColumnName"].ToString();but it only return that column name not value of the cellwhat's wrong? help me. thank u
11 Jul 2013 by MuhammadUSman1
Debugg code and Before initialization Check in Quick Watch that what exactly value of datatable cell have.//it should work. string value=dataTable.rows[0]["DataColumnName"].ToString();// but you can try this. hope so it'll work.// there is nothing wrong with your code.// 2 as column...
3 Jun 2015 by Grant Weatherston
I have a DataTable object, that i'm using to represent data in a view. The view is generic and therefore i want to just pass in data and display it on the page for all my models (rather than having a different view for each model, when all going to look the same visually).My problem is, i'm...
23 Oct 2010 by TweakBird
Accessing Value from System.Data.DataTable
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 =...
27 Oct 2010 by A.J.Wegierski
int empId = dt.Columns[EMP_ID].Ordinal;...int empId = Convert.ToInt32(dRow[empId]);
13 Jan 2014 by JOHNNYDEMICHAEL
csvData is a DataTable bound to a DataGridView. Compiles & runs no errors . . but after refresh, no new row appears in grid . . . ?? Is there something missing? private void addNewRowButton_Click(object sender, EventArgs e) { csvData.NewRow(); ...
13 Jan 2014 by OriginalGriff
Perhaps it would help is you added the new row to the table?DataTable.NewRow[^] just creates a new blank row with the correct schema / columns...
13 Jan 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
You need to bind the DGV again like below.private void addNewRowButton_Click(object sender, EventArgs e){ csvData.NewRow(); // Provide Column values for the New Row. DataGridView1.DataSource = csvData; DataGridView1.DataBind();}
25 Dec 2013 by Member 10467514
Here I created a grideview containging joblist.below that i added one datadetailview .when anybody select the row in gridview it will shown in detail view...I added one column checkbox in the detailview.when anbody select the checkbox and click apply button below ,the data in the detailview must...
25 Dec 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
On Apply Button Click Event, do the following things.Initialize a new DataTableLoop through the DetailsView Items/Rows. Inside the loop...Get the CheckBox Control by FindControl or somethingDetermine if it is Checked or not by CheckBox.Checked Property[^]If that is checked add that...
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...
27 Jun 2023 by OriginalGriff
This is your 49th question, pretty much all of which can be answered with a trivial google, or a little knowledge of the classes you are playing with. In this case, it's simple to work out what you need to do by thinking about a DataTable and...
26 Jul 2017 by Member 10484162
i Have a table which is already have textbox and button. i want when user click (Add) button then automatically add new row with same textbox and same button with add action. Below is my code. please help me how to i add new row, and my ( Product_name )textbox is auto complete feature. ...
26 Jul 2017 by omerkamran
Here I have used Simple Javascript instead of Jquery function AddNewRow() { var table = document.getElementById("product_table"); var row = table.insertRow(table.rows.length); var...
30 Oct 2012 by sharadpanwal
hi, i want to add image to datatble but getting an error.below is code i have done.Type of value has a mismatch with column typeCouldn't store in logoname Column. Expected type is Byte[].this error i got at this line...
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 ...
28 Apr 2014 by Declan Bright
A technique which ensures that an ASP.NET GridView displays nicely on small screen devices.
22 Feb 2012 by Ravi Sargam
I Have dgv with Rollno,StudName columns and DataTable dtStud which returns data like thisStudid Name Rollno StandardId1 AAA 1 12 BBB 2 13 CCC 3 1I want add this data to dgv(DataGridView) columns Rollno,StudNamethx in advance.
14 Sep 2013 by Grant Mc
I would like to write code to add a DataColumn to a DataTable, but when I save the DataTable, it does not include the new DataColumn.It saves any new DataRows I add, but not the DataColumns.Can somebody please tell me what I am doing wrong?public partial class Form1 : Form{ ...
14 Sep 2013 by Mahesh Bailwal
You can not add new column/field to database table using dataset or datatable you might need to use "ALTER TABLE" with ADO.NET commands. Check below linksHow Can I Insert New Column Into A Database Table Using SqlDataAdapter and DataTable?[^]adding a column to a SQL table in VB using...
31 May 2011 by butchzn
I am adding 2 columns to a table that belongs to a dataset. I perform this operation twice. In grid1 i am able to successfully add only 1 column("RefNum") whereas in grid2 both columns get added perfectly. No exception is thrown. Its as if the adding of the second column to grid1 did not happen,...
1 Jun 2011 by butchzn
Ok guys,I got it...phew,highlighted is the line of code that i was missing.i added the column before filling the dataset with data but just after i cloned the structure i need.Dim dataSetResults As DataSetDim foundRowsCancelling() As Data.DataRowDim...
9 Dec 2023 by Member 4529316
I have a Dataset with results I get from the DB, I keep that as a base dataset and would like any filtering will be done on the second Dataset. I ensure I have the filtered data on datatable but when I use dataset.table.add the dataset is...
9 Dec 2023 by Dave Kreskowiak
DEBUGGER! Ruin the code under the debugger and set a breakpoint on the line that fills the DataSet. Execture the code one line at a time and hover the mouse over variables to see their content. You could have figured this out in seconds! The...
15 Mar 2011 by Varun Sareen
Dear Friends,I have a dataset in which there are multiple tables for e.g. at index 0,1,2.I want to filter the table data at index 1, which i am doing and after the method (which returns the filtered datatable) returns the datatable..I want to add it to my existing dataset at index 1...
15 Mar 2011 by demouser743
ADO.NET enables you to create DataTable objects and add them to an existing DataSet. You can set constraint information for a DataTable by using the PrimaryKey and Unique properties.For more information check this http://msdn.microsoft.com/en-us/library/aeskbwf7%28v=vs.80%29.aspx[^]
15 Mar 2011 by avigodse
// /// Routine to filter first table and replace exiting table with filtered records. // // Dataset instance to be manipulated\n private void _FilterAndInsert(DataSet sourceSet) { ///Apply your filter clauses in Select() function...
21 Apr 2014 by Hareesh Malli
I want to create datatable in below format SNO column rank 1 c01 c02 c03 10 c11 c12 c13 c223 c22 c23So please help me my dear friendsTanks in advance
23 Apr 2014 by Asim Ghazanfar
Try thisINSERT INTO Data ( SNO )select 'C01'unionselect 'C02'OR INSERT INTO Table ( SNO ) VALUES ( C01, C02)
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...
10 Mar 2014 by nandakishoreroyal
tryDt.Rows.Add("Mike",new string[Dt.Columns.Count - 2]);
10 Mar 2014 by DipsMak
You can do this way also.....foreach (DataRow dr in ds.Tables[0].Rows){ dr["Name"] = "Mike"; dr["Id"] = 1;}
10 Mar 2014 by george4986
dont know ur data structure of table, which u didn't postedtry this string colName = "name from database "; /////more than one columns take the count DataTable dt1 = new DataTable(); /////more than one column case use below code inside a loop with count of columns ...
22 Dec 2017 by Dirk Bahle
Tips & Tricks on loading and saving WPF Tree View based content.
12 Jun 2014 by Member 9965416
retrieving data into data table and converting it to json string makes the page loading slow is there any better way to convert and load data
17 May 2017 by ddgjgj
Please find attached the application picture, where the column ORDER ID is not showing, and instead of that, is showing the PLUS sign. So all the columns should shift for one to the right. ajax And all the time when I run the application it shows me this error message: DataTables warning...
2 Oct 2016 by Gold$Coin
I am having Application slowness when i suppose to get distinct out a DataTable which has 50k+ records. i am using the below code to do it/// /// Generate Distinct Data Table from the Data Table Generated from server. /// Func
2 Oct 2016 by Timo Tielens
Please make a seperate thread so it will run on the background. Load first the things you need the most and so on and on. Search for Proactor Pattern, this explains how to make sure that your program keeps running.Quote:Proactor Pattern
24 Dec 2017 by User98743
I've been using a lot of DataTables lately. I haven't been adding the DataTable to a DataSet. I'm wondering if there are advantages to adding it to a DataSet when there's only one DataTable. I'm coding in C# Also, is this common practice? What I have tried: My DataTables aren't being added...
24 Dec 2017 by Dave Kreskowiak
No, there isn't. A DataSet is just a collection of DataTable objects and any DataRelations between them. If you're got only a single DataTable, there's no advantage at all.
17 Jun 2011 by Member 8015046
Hi everyone.I am new at making web applications. I am wanting to make a ASP.NET Dynamic Data Linq to SQL Web Application. I followed most of the Adventure example to get a simple table and showing up in the web browser. What I need help with is making the table in the web browser let me able...
18 Jun 2011 by ambarishtv
this will help you http://csharpdotnetfreak.blogspot.com/2011/04/gridview-examples-in-aspnet-20-35.html[^]
4 Oct 2013 by gtan018
I have an Asp.Net GridView that contains 205 columns. I can export it to an Excel with the save as prompt. The export to excel is working properly. My question here is can I create a simple LinkButton on the home page that says 'Export to Excel' without showing the entire GridView on a...
4 Oct 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Yes, why not.Just use the DataTable directly. Export DataTable to Excel. There is no need to bind the GridView.
6 Nov 2011 by Jovan Popovic(MSFT)
Create datatable with standard CRUD functionalites in ASP.NET MVC using the jQuery DataTables Editable plug-in
24 Feb 2013 by Nasser Abu Farah
HiLets say that I have a table with three columns. Name, Salary, Bonus.Now I want to create a gridView to represent the data in the table with a fourth column contains the bonus calculation ( salary * bonus).In other words, I will have a three columns table, and a four column...
24 Feb 2013 by Nasser Abu Farah
first of all thank you for your interesting,regarding the second comment by Sandeep Mewara, I read the data and made my calculation in a dataReader, but I don't know how to assign the value to a new column and and make the new column appear in the gridView.what I am really trying to do is...
24 Feb 2013 by vishal.shimpi
try the following solution...Once your retrieve data from database to DataTable the add one new column in the same data table like Assume your datatable name is dt then write, dt.Columns.Add(new DataColumn("Total", typeof(decimal))); foreach(DataRow dr in dt.Rows) { dr["Total"]...
24 Feb 2013 by Avik Ghosh22
SqlCommand cmd = new SqlCommand("SELECT * FROM RNDTABLE",con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt=new DataTable(); da.Fill(dt); dt.Columns.Add("GROSS_SAL", typeof(decimal), "(SAL +(SAL*.10))-100+5");GridView1.DataSource = dt; ...
27 Jul 2017 by Member 10484162
I have added autocomplete feature in my textbox but I click Add button then new row added but autocomplete wont work. below is my code. What I have tried: $(function() { $("#skills").autocomplete({ source: 'textbox_auto_complete.php' }); }); //Add Script ...
17 Nov 2013 by dolbol
Hi, all.I am trying Data Table Row delete or remove with vb .net, but i have some problem on Auto increment update after deleting Datatype Row.Kindly refer to the followings for my question.I am using Local ".csv" file for DB handling.1. I make one Data Table with one Auto increment...
19 Dec 2013 by Shweta Lodha
Automatic numbering for the primary key column
14 Jun 2017 by Ehsan Sajjad
A guide on how to implement gridview in ASP.NET MVC 5
30 Jan 2017 by M Oj
I have a xml file with the following format : aaa bb'b' 123 1234 12345 ...
30 Jan 2017 by #realJSOP
0) Use a class instead of a struct.1) Use serialization to load/save the xml.
14 May 2018 by creizlein
I have a DataGridView that could possibly switch its display values from 2 different dataTables, the information within is really simple, its a fixed 20rows x 20cols table. Each cell must contain an object, So when i select a cell i can display its extended properties like MaxValue, MinValue,...
18 Oct 2022 by f*rcklift2030
I'm a C# newbie working on a Winforms project and need help retrieving and displaying picture to picturebox. However, I'm getting an error "Unable to Cast object of type String to type byte[]" There are other elements such as Navigation that...
12 May 2022 by Manojkumar-dll
I have to Bind the datas from a Column in datatable into a custom search dropdown using jquery What I have tried: This is the HTML Part
12 May 2022 by Richard Deeming
So many things wrong with that code... Your element has an ID of ddl_type, but your script tries to reference an element with the ID ddltype. Those are two completely different IDs. You declare an array variable called $duplicate, but...
24 Sep 2012 by jawad59
Issue in binding multiple combobox and datagrid at a time. It just binds the last comobox/datagrid.SetConnection(); sql_con.Open(); sql_cmd = sql_con.CreateCommand(); string CommandText = "SELECT MediaArticle.id,...
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
24 Sep 2015 by Member 11999641
hi, I am going to find a value from a column in a gridview. If there are rows that have this value in that column, I will add those rows to a DataTable. Afterwards I will bind it to another gridview to display those rows out. However, when I tried to do this, columns that are in INT cannot be...
25 Sep 2015 by Sinisa Hajnal
I think correct version would be new DataColumn("STATUS", GetType(int)); or something very similar (writing from memory.
22 Sep 2010 by jamespeter
HiI have a datatable bound to a datagridview, using a bindingsource object. I have an external server that sends updates to my program. When the program receives the updates, it adds a new row to the datatable containing the new information. As the datatable is bound to the datagridview,...
26 Oct 2010 by shanawazway
Your scenario is like chat application.In which list is updated by the message.Try search chat application , u may have idea to update your GridView.
12 Jun 2014 by Anurag Sinha V
Hi,I have a GridView and I need to bind it with a dynamic Data Table.I have a List> and a List>.I need a DataTable with 3 columns, namely FileName, LastAccessTimeForServer1, LastAccessTimeForServer2.The List> would contain 2 lists of...
13 Jun 2014 by Debabrata_Das
Hello Anyurag, I tried the following code:DataTable dtForGridView = new DataTable();DataColumn dc1 = new DataColumn("File Name", typeof(string));DataColumn dc2 = new DataColumn("LastAccessTimeForServer1",...
8 Jun 2016 by partha143
I have an XML which has some music info in it. I'm reading my XML to DataSet through ReadXml method. Then creating a DataTable and getting the 1st table info of DataSet and I'm trying to bind DataTable to DataGrid in MVVM Pattern. Below is my MainWindow View: Binding my ViewModel to MainWindow...
8 Jun 2016 by VR Karthikeyan
Hi, refer the below function, it adds DataGridTextColumn dyn private void SetColumnsAndBinding(DataTable objTable) { DataGridTemplateColumn objRadioButtonColumn = new DataGridTemplateColumn(); DataTemplate RadioButtonCellTemplate = new...
18 Apr 2014 by Guruprasad.K.Basavaraju
I am not sure of Bootstrap but you can simply apply the same class to second TD using the Javascripts after the table is created.$(function() { $(".table-class tr").each(function() { $(this).find('td:eq(2)').addClass("hidden-xs"); });});
18 Apr 2014 by sunil gutta
HiI am trying to design my JQUERY DATATABLE for variable devices . So i want to hide some columns in my table . So for better Responsiveness and its advantages i choose BOOTSTRAP 3.0 Well i done everything but i am unable to FIND logic how to hide columns which are DYNAMICALLY...
5 Feb 2015 by Member 11432263
I have created an application in which I have used datatables and handler for binding data with datatable, where I have used JSON dataformat.When I request for the data First time all 100,000 records come in the datatable which is client side but when I click second time, At datatable...
9 Feb 2015 by Member 11432263
Thanks for your precious time. I got the answer. I am clearing the table data at every find click by using fncleartable().
5 Mar 2014 by FarhanShariff
I have built 2 DataTables from CSV files. I have to compare these DataTables (table1 and table2 to built table 3)I have Successfully Built the 2 tables but I don't know how to pass these tables as arguments and build the new table I get error when I try to Build the table3once table 3 is...
3 Mar 2014 by CHill60
The problem with line DataTable table3 = CompareTwoDataTable(DataTable table1,DataTable table2); is that you have left the type definitions in the call - cut&paste error perhaps?Change it to DataTable table3 = CompareTwoDataTable(table1,table2);
6 Mar 2014 by george4986
Quote:Neewbie, happy to hear u have the result. final working code is updated belowprivate static DataTable CompareTwoDataTable(DataTable table1, DataTable table2){DataTable table3 = new DataTable();DataRow dr = null;string filterExp = string.Empty;for (int i = 0; i
6 Mar 2014 by FarhanShariff
Quote:george4986 the code is working only thing to be changed is table3.Columns.Add(col, typeof(double));You are a Genius man Quote:private static DataTable CompareTwoDataTable(DataTable table1, DataTable table2) { DataTable table3 = new DataTable(); ...
10 Aug 2017 by Member 13356276
Okay, so I'm coding in C# and just starting out, and my first assessment is to take data from a CSV file and load it onto a list (must use a list) and then load that into a dataGridView in my Windows Forms App and then have it be editable. Now I have a decent idea how to do it once I have it in...
10 Aug 2017 by Graeme_Grant
Here is a working piece of code that shows how to get a CSV file into a DataTable. It won't take much to alter to do what you want for your "first assessment". public static DataTable ConvertCSVtoDataTable(string strFilePath) { DataTable dt = new DataTable(); using (StreamReader sr = new...
10 Aug 2017 by Graeme_Grant
Looking at your code sample, the myList variable is not in the scope of your dt() method. You need to pass the result from ReadValues(...) method and pass it to your dt() method ... something like public static DataTable dt(IList myList) { // code goes here } Then to call: var table =...
10 Aug 2017 by Patrice T
Quote: C# - list created in part of code can't be accessed from the rest You need to learn 'Variables scopes'. Depending on what you want to do, the place where you declare a variable matters. 3.7 Scopes (C#)[^] "A more formal definition is that scope is an enclosing context or region that...
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...
25 Aug 2021 by Richard Deeming
Quote: string cmdInsert = @"INSERT INTO SoldProducts (BookName, Amount, Price) Values('" + Convert.ToString(r.Cells[0]) + "', '" + Convert.ToString(r.Cells[1]) + "', '" + Convert.ToString(r.Cells[4]) + "')"; Not like that! Your code is...