Click here to Skip to main content
15,887,392 members
Everything / DataRow

DataRow

DataRow

Great Reads

by Petr Ivankov
Application of abstract approach to database domain
by Paul Brower
This tip will allow you to return the value from column X, where column Y matches your filter
by ASP.NET Community
We all know that we can sort the rows in DataTable by making a simple use of DefaultView. But now if i want a few conditional rows to be shuffled in
by David Catriel
How to get a list of data rows that caused an exception (or several of them) in a SqlBulkCopy operation

Latest Articles

by yuvalsol
Print DataTable, DataView, DataSet, DataRow[] to Console, StringBuilder or Stream
by Mehedi Shams
Create a data dictionary for your database tables
by Petr Ivankov
Application of abstract approach to database domain
by ASP.NET Community
We all know that we can sort the rows in DataTable by making a simple use of DefaultView. But now if i want a few conditional rows to be shuffled in

All Articles

Sort by Score

DataRow 

13 Jan 2011 by Simon_Whale
import the excel data and run an outer join queryAccess Outer join query[^]
24 Feb 2011 by Henry Minute
If the code you have posted is accurate you open your SqlConnection (con) and then immediately close it again without doing anything with it.You might consider doing something like con.Open(); adapter1.Fill(dset1); con.Close();or reading the data in some other way.
18 Aug 2014 by Karthik Harve
Hi One rule with FOREACH loop is that, you cannot modify the loop collection. So try using FOR loop.try this.for(int i=0; i
29 Jan 2020 by TheRealSteveJudge
You can use so-called DataGridTemplateColumns. First you must switch off the automatic generation of columns by setting the AutoGenerateColumns property to "False". Then you must provide a template for every column. This example however just shows you how to define the templates for the first...
9 Sep 2010 by Dave Kreskowiak
Well, you can't avoid the loop. It's got to be done somewhere.For something like this (I'm not a SharePoint guy) if the data is all on an SQL Server, I'd probably have the SQL Server do the work in a stored procedure since it's better optimized to handle large data sets.
11 Jan 2011 by fjdiewornncalwe
There isn't a lot for us to go on. Show us the code you use to create and initialize these objects and we maybe then can provide you with some help.
14 Jan 2011 by #realJSOP
Why don't try you using LINQ instead?Even better, try using multiple threads in a thread pool to do it.
16 Nov 2011 by lukeer
There are two problems in the code you posted.1. Classes cannot inherit from instances.You wrotePublic class ClassA : DataSet1.DataRow1This makes the class ClassA inherit from DataSet1.DataRow1. From the usual naming conventions, this looks like DataRow1 is an object of type...
19 Dec 2011 by Un_NaMeD
Hey everyone.I have a DataTable which is bind to dataGridview in my code.When I get datas from database, the gridview works fine. it fills with data.What I want to do is getting the index(actually the value of the Primary key) of the of the specified row.How can I do it?Me best...
22 Feb 2013 by azinyama
This is what I have come up with. Any comments on if, or if there is a better way:DataRowView[] drv = e.GroupItems.Cast().ToArray();DataRow[] rows = (from dr in drv select dr.Row).ToArray();
14 Jan 2014 by walterhevedeich
Assuming your DataSource is accessible inside that event, and assuming the index in your code really points to the index of the DataRow on your DataSource, you can try doing the following:int index =...
18 Jan 2014 by Petr Ivankov
Application of abstract approach to database domain
8 Aug 2016 by Karthik_Mahalingam
try thisDataTable DT = new DataTable();DT.Clear();DT.Columns.Add("نام");DT.Columns.Add("نام خانوادگی");DataTable dtNew = db.TblUsers.Where(x => x.Id != 0).Select(k => { var row = DT.NewRow(); row.ItemArray = new object[] { k.Name, k.Family }; return row; }).CopyToDataTable();
21 Feb 2018 by RDBurmon
yes it will , but that should not be in limited scope, you have to declare your data model globally c# - How to Edit a row in the datatable - Stack Overflow[^] How to: Edit Rows in a DataTable[^]
21 Feb 2018 by Karthik_Mahalingam
Quote: If I do as such. Will the DataTable dt be updated with these values? Yes, only the filtered rows in the dt will get updated to new value. Quote: Since I am working to create a Windows Service, debugging would be a pain. Hence, asking here. You could have created a simple console...
27 Feb 2018 by F-ES Sitecore
Try Parallel.ForEach How to: Write a Simple Parallel.ForEach Loop | Microsoft Docs[^] There is no guarantee it'll increase performance, there are many factors involved in that such as how many cores on your site's server, the SQL server architecture and all sorts. You're more likely to get...
15 Jul 2010 by Paul Brower
This tip will allow you to return the value from column X, where column Y matches your filter
9 Sep 2010 by jabit
The situation:I've got a datatable filled with data from a sharepoint list. That table has an ID column which is the PK of a table that I have in an external LOB database. In the sharepoint table I've added a second column to contain data from the LOB datatable. What I need to is take the PK...
15 Sep 2010 by jabit
I finally solved this problem myself. I serialized the data into XDocument's in memory and performed the swaps using XElement.Add() to set the missing cell values. There's a tiny bit of extra overhead converting the DataTable to XML and then back but overall my code is now nearly 30% faster!
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...
21 Dec 2010 by Dave Kreskowiak
If you expect all the controls to be bound to the save record, then no, you cannot preserve the contents of the label.But, if the label was being bound by its own BindingContext, then you can have multiple sets of bindings instead of the forms default where all the controls are bound to the...
22 Dec 2010 by Alexander Dickbauer2
For example I have articles and categories and I want to show an article list in a DataGridView and I want to display (of Course not editable) the name of the category in a column. Is there a possibility to solve this without a view on the database? Because a view isn't updateable. Why isn't it...
22 Dec 2010 by Henry Minute
Why not list the Categories in a ListBox/ComboBox. Then if your relationships are set up correctly the DGV should show the articles in that category.
7 Jan 2011 by wizardzz
I haven't tested, but could you give this a try?for (int i = 0; i
7 Jan 2011 by jerrykid
To Getting DataRow into a DataGridViewRow you can try this codeDataRow dr = GridNCRView.GetDataRow( GridNCRView.FocusedRowHandle ); //Declare a DataGridView variable to hold this row //e.g, DataGridView gv = new DataGridView (); ...
11 Jan 2011 by Alexander Dickbauer2
In my Project i have a Big Data Set with many Relations. And when i try to use the DataRow Object of an Article i have a Property Category_ID and a generated Property CategoryRow. But whenever I access the CategoryRow it is always null. When I try to use the GetParentRow(DataRelation) it is also...
12 Jan 2011 by jamesdk8
After doing some more research I have found that this is not the way to go. I'm closing this issue.
13 Jan 2011 by MaulikDusara
I have two files (1) Access (2) Excel in both there are many records available. There are more than 50000 and I want to find out how many new records are not available in Access which are in Excel. :confused: both files structure are not the same. There is just one identical column in both...
3 Feb 2011 by Eddie Niebruegge
I have a form with a datagridview control where an operator may or may not change the value in the cells. If any data is changed, I want to update the database with the updated row. In the UpdateRow function I'm using below, the argument received, intDetailID, is a unique key in the table to...
3 Feb 2011 by Henry Minute
If DetailID is an Identity or a Primary Key, that might be the cause of the problem.See the Rules for Automatically Generated Commands section on This MSDN Page[^].
8 Mar 2011 by se.nishant
i want data from a label of data list in asp.neti created a template of data list and use a labelafter binding data in label i want to access the value of label
8 Mar 2011 by Niranjankr
You can try :string id=((lable)Datalis1.findcontrol["lable1"]).Text;
8 Mar 2011 by m@dhu
foreach (DataListItem dli in DataList1.Items) { Label Label1 = dli.FindControl("Label1") as Label; string lblValue=Label1.Text;}//In Datalist events.Label Label1 = e.Item.FindControl("Label1") as Label;//can get the value in string...
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...
4 May 2011 by Karthik. A
What about sp_executesql (if available in sybase)? You could combine all the insert statements as a single statement separated by ';' and call sp_executesql or something similar in sybase. I guess every database should have something similar to this.Also, I am not sure if this is the best...
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...
4 May 2011 by SilimSayo
If you were to use only SQL Server to SQL Server, you can use SQL Server Replication
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...
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 :...
5 Oct 2011 by Jürgen Röhr
Hi Alexander,you're assigning incompatible (non-castable) objects. A DataRow (which is in DataTable2.Rows) has nothing in common with a DataGridViewRow (which is in dataGridView1.SelectedRows).You have to add the data to the table by creating a new row (only if you have inherited from...
5 Oct 2011 by the headless nick
you can't use datatable like that...use somthing like datarow to pick data and add it row by row in a temprory table then you may copy data from that datatable to anothor dataset. DataTable dt = new DataTable("nicktable"); dt.Columns.Add("col1",...
6 Oct 2011 by BobJanova
There's two mistakes here: first, you are trying to copy the grid row, not the underlying row, and second, you need to clone the row before adding it as the same row object is not allowed to be in more than one table.I think you...
20 Oct 2011 by chiru_sri
Read the excel file into dataset and convert the each row data into given XML format and save it in the database.My Excel file contains the rows : Name, Description, state , provision etc.XML template format is : [Data from excel row [Data from excel...
14 Nov 2011 by Jimmy Beh
I'm having problem to inherit Typed Datarow to be implemented in my coding. my question is, what is the right method to inherit a Typed Datarow from a class and then initialize it in another class?eg:Public class ClassA : DataSet1.DataRow1{ public ClassA(DataRowBuilder rb) : base...
24 Nov 2011 by MrZedSven
I think this might be faster.licenceTable.DefaultView.RowFilter = "DriveKey = '" + selectedKey + "'"For Each row In licenceTable.DefaultView row("Location") = selectedLocalNextJust remember to set the RowFilter to nothing before referencing thedefault view...
19 Dec 2011 by girish sp
public static int Getindex(string row,DataTable dt) { int id=0; string rowvalue = row; try { id = (from DataRow dr in dt.Rows where (string)dr["Description"] == rowvalue ...
19 Dec 2011 by Code 89
Set datakeyname to select particular row form DB...GO THRU THIS LINK FOR MORE DETAILS ON ADD AND EDIT..gridview-datakey-valueEdit_update
8 Jan 2012 by MohammadIqbal
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using...
8 Jan 2012 by Wendelius
Didn't go through all the code but if the problem is simply that the InelliSense isn't making any suggestions, why not write the proper type by hand. There are several cases when Intellisense doesn't give up-to-date suggestions.
27 Jan 2012 by MohammadIqbal
DataGridColu...
26 Jan 2012 by Dean Oliver
Hi when I run your code it works perfectly. Is it not because you may be setting the style for the DatagridColumnHeader in XAML as well? And when are you initialising this code? Can you maybe attach your xaml for your datagrid control please.
30 Jan 2012 by Dean Oliver
Remove your namespace reference of dg: and add this xaml FontSize="16" FontStyle="Italic" CanUserReorder="True" CanUserSort="True"...
25 Jun 2012 by Richard C Bishop
I have an application that converts .xlsx files into .txt files. On one of my files, there are multiple agencies I need to separate and write the similar ones to their own file. For example, There is an agency 55 and agency 99. There are several entries of each and not necessarily in order. I...
25 Jun 2012 by snorkie
Maybe I'm oversimplifying the issue here, but try the following. In your last loop, try the following ////Print out all the values foreach (DataRow dr in dt.Rows){ StringBuilder sb = new StringBuilder(); string agencyNumber; int index =...
21 Jul 2012 by Chiranthaka Sampath
I want to get records from a database table to an array which will be multidimensional or one dimensional. How can I do that?Thanx!
22 Jul 2012 by woutercx
Maybe this will help:http://www.programmersheaven.com/mb/VBNET/408131/408131/multidimensional-array-within-a-structure/[^]
29 Jul 2012 by sant.rajas
Thanks strogg. You are absolutely correct.Actually my problem is I am dynamically setting the data like SerialNumber etc in newly created row which gets updated into datasource and then goes to the client side where this new row is reflected in datagrid.I have an idea about solving this...
6 Aug 2012 by Pankaj Nikam
It looks as if Visual Studio is confused. The event you mentioned, does exist in the code. What you can do is try restarting Visual Studio and running. If that does not help, try cleaning out the temporary asp.net websites folder located at...
4 Oct 2012 by Mohannad Khaled Maglad
Datatable dt2=getEmaployeeData(); foreach (DataRow erow in dt2.Rows) { employeeid = erow["employee_code"].ToString(); employeeName = erow["employee_name"].ToString(); hodID =...
4 Oct 2012 by fjdiewornncalwe
You are accepting changes before adding the new row. Nothing will happen then.DataRow sh*t = finleTable.Rows[i];finleTable.AcceptChanges();finleTable.Rows.Add(dr);Try this:DataRow sh*t = finleTable.Rows[i];finleTable.Rows.Add(dr);finleTable.AcceptChanges();
1 Nov 2012 by Ali_100
Hi I have a dataset ,I need to insert a copy of entire row in newly created row when the condition is matched in the dataset.I am having issue in copy the entire row & inserting.
8 Jan 2013 by amit_upadhyay
hi please check this codeFor icnt As Integer = 1 To 100 Me.SetText(icnt) Dim gd As String = "" Dim gl As String = "" Dim cr As String = "" Dim lr As String = "" Dim tbs As String = "" Dim srt As String = "" Dim fp As...
8 Jan 2013 by Bernhard Hiller
When you show the MessageBox, there is enough time for the other thread to be executed till you clicked the messagebox away. When you do not show the messagebox, you'll have a long queue of new threads which are executed after your loop ended. And all those new threads received your list...
22 Feb 2013 by azinyama
Good day all!!!I have a DataRowView array that I'm creating as below:DataRowView[] drv = e.GroupItems.Cast().ToArray();My question is how do I get a DataRow array (DataRow[]) for the 'drv' using drv.Select()???Or do I have to actually have to do it using a foreach...
27 Feb 2013 by Prafulla Sahu
I have a gridview with some data.I have a small requirement that if I will click on any row of the gridview then it will select and unselect the selected row if I will click outside of the gridview.I did everything except how to unselect the gridview row if I will click on outside of the...
27 Feb 2013 by _Amy
You can try using :MyGridView1.SelectedIndex = -1; But this is a server side code. You need to fire this on JavaScript page click event(Use __doPostBack( 'target', 'args')). Also check : How to use __doPostBack function[^].--Amit
6 Jun 2013 by dj_naveen
Hi, Help me to sort the below issue. I have a Dataset and the Dataset has Tables with 'n' number of rows. I want to display first 5 rows from the table in dataset. My Page will refresh every 1 minutes.So Whenever my pages is refreshing I need to display the next 5 rows from the...
6 Jun 2013 by Ahmed Bensaid
Hello,Have a look at : Paging Through a Query Result
13 Jun 2013 by Member 10073174
Hi, I'm developing an Application on Windows Mobile 6.5 and I have to implement a DataGridControl with alternating Row-BackColors.So I've written a class that inherit from DataGridTextBoxColumn to paintevery second row in another color. Problem is now that i have to setthe column...
7 Aug 2013 by azinyama
Good day all!!!I have a DataTable that I'm looping through:foreach (DataRow r in table.Rows){}I also have a class that inherits DataRow:public class OutlookDataRow : System.Data.DataRow{ public OutlookGridRow OutlookRow { get; set } public...
8 Aug 2013 by OriginalGriff
You can't - you cannot cast "up" the inheritance tree as the system would have to "invent" information for new items in the derived class. Since it doesn't have a clue what you added or what you want to do with it, it won't even try.The best solution is probably to define a constructor for...
11 Oct 2013 by ASP.NET Community
We all know that we can sort the rows in DataTable by making a simple use of DefaultView. But now if i want a few conditional rows to be shuffled in
15 Oct 2013 by Ashish159
(Check out the pics to understand by clicking the link)I have made the following WinForm in which the user provide book details and create a book record. This book record gets added to the dataGridView with the checkBox automatically...
15 Oct 2013 by MayurDighe
Ashish ....You have a Good Programming Skills...I like your GUI for your concern project.lets come to problem....The part of coding stuff you gave here is somehow complicated to understand..But...still I will try to help you...I think you are Updating a DataGridView after 'Book...
14 Jan 2014 by Karthik_Mahalingam
Try this..private void button1_Click(object sender, EventArgs e) { // foreach (DataGridViewRow row in dataGridView1.SelectedRows) // for row selection foreach (DataGridViewCell cell in dataGridView1.SelectedCells) { var...
12 Aug 2014 by Code.Combustion
Hi Chandra,If I understand correctly, you're trying to update values in the second table, based on values in the first table("DiagnosisFaultDescription1" and "RecommendationDetails") -- however the second table doesn't have column names (I'm assuming the table schema is the same in both...
2 Sep 2014 by KergalBerlin
Hi community,I am new to parallel coding and have some trouble understanding what I have read about it. Let's assume the following scenario: I have 5 tables in a sql server and I receive data from source X which needs to be filtered,sorted and validate and the resulting string[][]...
21 Oct 2014 by chandra sekhar
I want to know the count of specific strings present in the datatable var Contact = (from DataRow dr in dtRec.Rows where dr["Recommendations"] == strContactVibration select dr).ToList();but i am...
21 Oct 2014 by Mukesh Ghosh
Use Tostring ,it should work likevar Contact = (from DataRow dr in table.Rows where dr[Recommendations].ToString() == "m" select dr).ToList();
9 Aug 2016 by misaqyrn9677
Convert LINQ to DataTable ResultsI would like to write a query that rather than say .Tolist () in Linq & Lambda output of the DataTable back, please help MeFor example, the following codevar query = db.TblUsers.where (x => x.id! = 0) .Tolist ();The output of the code above...
21 Feb 2018 by IMFAMOUS
I am a newbie in dot net framework. So here's the problem: I imported a list of users from excel to a DataTable named 'dt'. Now in another function that I am passing my dt DataTable to, I am creating a list of DataRow and initializing as below: List rows = dt.Select([LAN...
2 Mar 2018 by George Swan
I would use a SemaphoreSlim. This is a class that 'gates' the number of concurrent reads of a database to a preset level. Once that level has been reach, an existing read has to finish before a new read is allowed to start. //A method to asynchronously load data from the database private async...
2 Mar 2018 by Dave Kreskowiak
While ADDING rows to a DataTable? Not really. From the MSDN documentation on the DataTable: Quote: This type is safe for multithreaded read operations. You must synchronize any write operations. While it is possible to use multiple threads to add records to a DataTable object, adding rows to a...
10 Oct 2018 by bryandkko
DataRow dr; dr = ((dgv.DataSource) as DataTable).Rows[dgv.CurrentRow.Index]; dgv is DataGridView predefined on winform. dr is single always. What I have tried: Above code was found. But it doesn't work right. Because 'CurrentRow.Index' is not macthed to 'DataTable's Index'. I think to copy...
10 Oct 2018 by OriginalGriff
Use the CurrentRow item and it's DataBoundItem property: for me, it returns a DataRowView which lets me access the Row itself: DataRowView drv = myDataGridView.CurrentRow.DataBoundItem as DataRowView; if (drv != null) { ...
12 Aug 2019 by sophia kylie taylor
Hi, is there any way I could display a data to the datagrid view Columns through depending on the value of a cell. I was working for a program relating a time and attendance system that would disperse the data from the csv file to the correct data column on the datagrid view. What I want to...
12 Aug 2019 by Richard MacCutchan
A better way is to use the Jet or ACE engines to read the .csv into a form that you can bind directly to the DataGridView. See Using OleDb to Import Text Files (tab, CSV, custom)[^], it's C# but should be fairly easy to convert.
4 Sep 2019 by Member 14532396
I have defined this datagridviewcombobox: Dim lCol2 As New DataGridViewComboBoxColumn lCol2.DataPropertyName = "Descrizione" lCol2.DisplayMember = "Descrizione" lCol2.ValueMember = "IDTessera" lCol2.DisplayIndex = 2 dgwNote.Columns.Add(lCol2) ...
4 Sep 2019 by Gerry Schmitz
DataTable.NewRow Method (System.Data) | Microsoft Docs[^]
10 Nov 2019 by Chirag Sudra
I am using a common method to convert DataTable to List>. I am getting some float values in DataTable, values are correct but on putting loop on DataTable to fetch values, I first get DataRow. This is the time where my values gets changed. Eg. Value in DataTable cell...
29 Jan 2020 by Grant Mc
Hello. I would like to place a datagrid in my WPF application, that will be bound to a MYSQL database. Simple enough. However because there are so many fields, and they will not all display on the screen at once (you will need to scroll bar to see the other fields), I would like to display my...
27 Oct 2022 by NPetey
I am using VB.Net Windows form with a Datagridview and a retrieve button. The form is used by end users who paste job number numbers in column 0, then click the retrieve button and the data from the database will display in the grid. The code I...
27 Oct 2022 by Dave Kreskowiak
Are you sure that SQL statement is good and returning the proper rows? Somehow, I doubt it. This is what it looks like when you properly format the SQL and capitalize all the keywords: SELECT U.SearchKey , pj.LOCATION_CODE ,...
19 Jun 2012 by David Catriel
How to get a list of data rows that caused an exception (or several of them) in a SqlBulkCopy operation
24 Nov 2016 by Mehedi Shams
Create a data dictionary for your database tables
9 Nov 2017 by yuvalsol
Print DataTable, DataView, DataSet, DataRow[] to Console, StringBuilder or Stream
30 Oct 2011 by DrABELL
ASP.NET GridView control hosting another GridView in data-centric web applications
4 May 2011 by JohnLBevan
Hi Guys,I'm trying to insert multiple rows into a database. Rather than looping through all records and inserting them one at a time, I'm hoping to be more efficient and do a bulk insert (i.e. one statement to send all data in one go). Do you know if there's a way to do this? FYI: I'm...
27 Jul 2012 by strogg
The NewRow() simply creates a row with the schema of the table. It does not add the row to the DataTable & you cannot get the index until you add the new row to the table. Here's an example(assuming dt is the DataTable)Dim row As DataRow = dt.NewRow()' IndexOf() will return -1 if called...
6 Aug 2012 by JammoD87
Hi,I am trying to add a total to the bottom of a DataBound GridView. I recently asked how to acheive this on here and I got the help I needed. After following one of the tutorials that were given in the answer. I now have an error, everytime the page try's to load.The error I am...