DataRow is an ADO.Net class that represents a row of a data in a DataTable.
Questions tagged [datarow]
755 questions
4
votes
1 answer
How does the IConvertible interface work with DataRow?
I'm just wondering how the Convert class and IConvertible interface works with a DataRow. If I have this code:
string s="25";
int x= Convert.ToInt32(s);
The call to Convert.ToInt32(s) will run the following:
((IConvertible)s).ToInt32()
So how does…

Roman
- 565
- 1
- 10
- 27
4
votes
2 answers
Compare two datarows
I have a datatable with multiple rows inside it. I have got 1 more row and I want to check if this row is a duplicate of the existing rows in the datatable. So I tried like:
DataTable dataTable = GetTable();
if (dataTable.Rows.Count > 1)
{
for…

Sandy
- 11,332
- 27
- 76
- 122
4
votes
1 answer
How to determine a DataGridViewRow from the DataRow it is bound to
I would like to change the forecolor of a DataGridViewRow when a DataTable event is fired (specifically the DataColumnChangeEvent). In order to do so I need to get the associated DataGridViewRow of the row the event occurred on.
I have the…

developer
- 7,252
- 14
- 49
- 57
4
votes
2 answers
print an entire table in C#
I'm trying to print the content of a DataTable, starting with the column headers, followed by the content of the table tupples.
output.Add($"Table : [{dataTable.TableName}]");
string strColumnNames = "";
foreach (DataColumn col in…

Dominique
- 16,450
- 15
- 56
- 112
4
votes
1 answer
How to commit these data row changes back to the DB
I have not really worked with datasets before. I use a lot of LINQ / Entity Framework.
Here is the code I have written (it is one part of a switch):
if (!DataHelper.DataSourceIsEmpty(dsUp))
{
//get datarow…

Phil
- 1,811
- 9
- 38
- 60
4
votes
1 answer
How to create an object from a Datarow of Datatable in Flutter
I'm quite new to flutter and I'm building a shopping app, which list the order items in a table. The user will fill out the row field such as Price and Amount. I want to know how do I create an object of order items from each row of table. Please…

Coldie Man
- 45
- 1
- 1
- 6
4
votes
7 answers
generic field getter for a DataRow
I try to extend the DataRow object with this generic method :
public static T? Get(this DataRow row, string field) where T : struct
{
if (row.IsNull(field))
return default(T);
else
return (T)row[field];
}
It's work fine when T is…

A.Baudouin
- 2,855
- 3
- 24
- 28
4
votes
2 answers
Convert DataRow value to strongly typed value
I want to convert a value from a DataRow to a strongly typed variable. I thought about something like:
int id = row.Field("ID");
But the problem is, that our standard Db-Select returns a DataTable where every value is type of string. Means…

Sebi
- 3,879
- 2
- 35
- 62
4
votes
1 answer
How can this code be further optimized?
I just got a code handed over to me. The code is written in C# and it inserts realtime data into database every second. The data is accumulated in time which makes the numbers big.
The data is updated within the second many times then at the end of…

mustafabar
- 2,317
- 6
- 31
- 47
4
votes
2 answers
How do I create a method that converts a DataRowCollection to an array of objects of a generic type in C#?
I am trying to create a method that takes a DataTable or a DataRowCollection and converts it to an array of a generic type. Something like this:
public static T[] ConvertToArray(DataTable dataTable)
{
List result = new…

Olle
- 43
- 1
- 4
4
votes
1 answer
How to have inherited DataRow class so inherited DataTable can have DataTable.NewRow()
So I would like to extend the DataRow class by adding int to the class Obviously it is simple
public class DataRowWithInt : DataRow
{
// Properties ///////////////////////////////////////////////////
public int integer
{
get;
…

Shintaro Takechi
- 1,215
- 1
- 17
- 39
4
votes
1 answer
Handle DataTable.DataRow cell change event
I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Tom Smykowski
- 25,487
- 54
- 159
- 236
4
votes
1 answer
Passing a datarow to a form and binding the controls to it
Many hours of internet searching has revealed no definitive answer on this question, so I thought I would re-hash it. I need to pass a datarow to a form then bind the controls in that form to the values in the datarow. The Datarow was created by a…

Elcid_91
- 1,571
- 4
- 24
- 50
4
votes
5 answers
How to convert a List into DataTable
I'm getting values from another data table as input to list. Now i need to save those list values into another DataTable.
List:
List list = slectedFieldsTable.AsEnumerable().ToList();
foreach (DataRow dr in slectedFieldsTable.Rows)
{
…

Ganeshja
- 2,675
- 12
- 36
- 57
4
votes
4 answers
avoid checking for DataRow.IsDBNull on each column?
My code is 2x longer than it would be if I could automatically set IsDBNull to "" or simply roll over it without an error.
This is my code:
Dim conn As New SqlConnection
conn.ConnectionString = Module1.DBConn2
Dim sqlCommand = New SqlCommand("SELECT…
user1382306