Click here to Skip to main content
15,896,118 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 Updated

DataRow 

20 Apr 2023 by chandra sekhar
if (NSFwithExtOrSerFound) { int count = 0; foreach (DataRow recRow in dtRec.Rows) { if (recRow[0].ToString() == "Contact Vibration Specialist") ...
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 ,...
1 Feb 2021 by Member 15061586
i chose the last solution.solution 2. but after the table name there is no acceptchanges() option.
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...
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...
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...
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[^]
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.
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...
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) { ...
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) { ...
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...
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...
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...
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...
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...
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[^]
9 Nov 2017 by yuvalsol
Print DataTable, DataView, DataSet, DataRow[] to Console, StringBuilder or Stream
24 Nov 2016 by Mehedi Shams
Create a data dictionary for your database tables
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...
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 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();
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...
2 Sep 2014 by kbrandwijk
You have a string[][]:string[][] myArray = new string[][] {};You can either use one method for all tables, or define a separate method for each table.Using one method for all tables, you define a list of tablesList tables = new List { "table1", "table2", "table3",...
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[][]...
18 Aug 2014 by ChauhanAjay
You will need to change the delete statement in the following formatdt.Rows.Remove(dr);dt.AcceptChanges();where dt is the data table from where you would like to delete the row and dr is the particular row which needs to be deleted.
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
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...
12 Aug 2014 by chandra sekhar
I have two tables in a dataset and based on one table values i have to modify another table value and display it in the view. DataTable dt = _dsexportData.Tables["DiagnosisFaultDescription1"]; DataTable dt1 = _dsexportData.Tables["RecommendationDetails"]; ...
15 Apr 2014 by avelsamy
Hi Friends,I am also acing same pronlemafter changes the error occured like thisMethod 'Protected Sub GridmailDetails_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs)' cannot handle event 'Public Event RowDataBound(sender As Object, e As...
18 Jan 2014 by Petr Ivankov
Application of abstract approach to database domain
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...
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 =...
14 Jan 2014 by JOHNNYDEMICHAEL
My DataGridView is bound by DataTable (csvData). Since the grid mirrors the table, I'm thinking . . . this.DataGridView1.SelectedRows.Count would be the same row of the table. But how do I assign that selected row to the row (DataRow) of the table so I can delete it? private void...
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...
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...
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
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...
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...
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...
6 Jun 2013 by Ahmed Bensaid
Hello,Have a look at : Paging Through a Query Result
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...
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
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...
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();
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...
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...
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...
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.
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();
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 =...
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...
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...
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...
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...
27 Jul 2012 by sant.rajas
Hello,On some event, I am adding a new row in DataTable using NewRow function. which results in calling another event of DataTable "OnColumnChanged". I want to get a RowIndex of recently added row.When I try to obtain row index of newly added row using code : lDataRow =...
22 Jul 2012 by woutercx
Maybe this will help:http://www.programmersheaven.com/mb/VBNET/408131/408131/multidimensional-array-within-a-structure/[^]
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!
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 =...
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...
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
30 Jan 2012 by Dean Oliver
Remove your namespace reference of dg: and add this xaml FontSize="16" FontStyle="Italic" CanUserReorder="True" CanUserSort="True"...
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.
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.
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...
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
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 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...
4 Dec 2011 by thatraja
Check these threadsHow to write a datarow to a xml file[^]How can I turn a DataRow into an XML string using C#?[^]
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...
24 Nov 2011 by Eduard Lu
I believe this one is already good enough as per performace.Goodluck on you. Please share us if you find a better one :)
24 Nov 2011 by MrZedSven
Is there a better way of doing this?For Each row In licenceTable.Rows If row("DriveKey") = selectedKey Then row("Location") = selectedLocal End IfNext
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...
14 Nov 2011 by OriginalGriff
By the looks of it, you are trying to inherit a class from a specific instance of a DataSet, and a specific instance of it's rows (which it dowesn't have anyway - a set has tables, which have rows)You can't do that: inheritance does not work from a specific instance, it works from generic...
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...
14 Nov 2011 by Abhinav S
You need to have a default constructor with no parameters in classA.Since you have defined a constructor with a parameter (DataRowBuilder) the original constructor is unavailable.Or else, you can pass a new DataRowBuilder object when you create an instance of classA.
30 Oct 2011 by DrABELL
ASP.NET GridView control hosting another GridView in data-centric web applications
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...
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 :...
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...
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",...
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...
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...
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,...
4 May 2011 by SilimSayo
If you were to use only SQL Server to SQL Server, you can use SQL Server Replication
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 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 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...
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...
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...
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...
8 Mar 2011 by Niranjankr
You can try :string id=((lable)Datalis1.findcontrol["lable1"]).Text;
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
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.
24 Feb 2011 by darkoSE
Hello everyone.I am trying to add a row to my database.This is the code i have been using: public bool Insertdata(string Name, string LastName, string Sex) { System.Data.SqlClient.SqlConnection con; System.Data.SqlClient.SqlDataAdapter adapter1; ...
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...