DataRow is an ADO.Net class that represents a row of a data in a DataTable.
Questions tagged [datarow]
755 questions
10
votes
2 answers
Change Datarow field value
First I have last update file from DB
DataTable excelData = ReadSCOOmega(lastUploadFile);
, after this iterate over this data
foreach (DataRow currentRow in rows)
{
currentRow.
}
Is that possible to change da data in the foreach loop.I can…

Dany
- 367
- 1
- 2
- 21
10
votes
5 answers
what is the correct way to read from a datarow if the cell might be null
I have the following code which seems to blow up if the column in the datarow (dr) is null. what is the correct way to parse out the value from the data row and handle null checks?
Person person = new Person()
{
FirstName =…

leora
- 188,729
- 360
- 878
- 1,366
10
votes
3 answers
Get Value of Row in Datatable c#
i have a problem with my code.
foreach (DataRow dr in dt_pattern.Rows)
{
part = dr["patternString"].ToString();
if (part != vpart)
{
System.Console.WriteLine(part);
System.Console.WriteLine("Geben Sie bitte für…

subprime
- 1,217
- 8
- 20
- 34
9
votes
1 answer
How to use "deep" XML with MSTest XML Datasource
I'm having some problems with MSTest using an XML Datasource. Assume that I've got an XML file that looks like this:
1
Mike
Paterson
…

devlife
- 15,275
- 27
- 77
- 131
9
votes
1 answer
Check if WPF DataRowView contains a column
I can get the value of a column in a DataRowView using
DataRowView row;
object value = row["MyColumn"];
of course, if there is no "MyColumn" in the DataRowView, this code throws an exception.
How do I check in advance, if the row contains…

Sam
- 28,421
- 49
- 167
- 247
8
votes
1 answer
C#/winforms: how to best bind a propertygrid and a System.Data.DataRow
i have System.Data.DataRows with several fields, most of them just plain types like int, single, string.
what is the best way to make them editable using a propertygrid?
it should work automatically no matter what kind of fields the datarow has, but…

clamp
- 33,000
- 75
- 203
- 299
8
votes
3 answers
How can I assign a DBNull in a better way?
I need to parse a value from a DataRow and assign it to another DataRow. If the input is valid, then I need to parse it to a double, or else add a DBNull value to the output. I'm using the following code:
public double? GetVolume(object data)
{
…

Mike
- 3,204
- 8
- 47
- 74
8
votes
4 answers
extract values from DataTable with single row
How to extract the values from data table having single row and assign to asp labels.
private void GetUser(string userId)
{
dbr.SelectString = "select name, gender, address, contactno from userInfo where id = = '" + userId + "' --"; // return…

user4221591
- 2,084
- 7
- 34
- 68
8
votes
3 answers
Check if a column with a given name exists in a datarow
How can I check if a column exists in result that populate a listview?
The listview is populated from a stored procedure.
This is what I tried but no success:
<%# Container.DataItem.GetType().GetProperty("Phone")==null?"phone is null":"we have…

POIR
- 3,110
- 9
- 32
- 48
8
votes
2 answers
DataTable select method with single quote conflict C#
I recently found when I do a LINQ select under a field that contains an apostrophe, it makes my application to throw an exception.
DataRow[] newDr = this.ds.Tables["TableName"].Select("Name = '" + drData["Name"].ToString() + "'");
If drData["Name"]…

Maximus Decimus
- 4,901
- 22
- 67
- 95
7
votes
11 answers
Is it better to use the column name or column index on .Net DataSets?
When retrieving values from a DataRow is it better to use the column name or column index?
The column name is more readable and easier to maintain:
int price = (int)dr["Price"];
While column index is just faster (I think):
int price =…

tpower
- 56,100
- 19
- 68
- 100
7
votes
3 answers
If I'm updating a DataRow, do I lock the entire DataTable or just the DataRow?
Suppose I'm accessing a DataTable from multiple threads. If I want to access a particular row, I suspect I need to lock that operation (I could be mistaken about this, but at least I know this way I'm safe):
// this is a strongly-typed…

Dan Tao
- 125,917
- 54
- 300
- 447
7
votes
2 answers
Convert DataRow to Object with AutoMapper
I can successfully map from IDataReader to a List of objects but when I want to take one DataRow it doesn't seem to work as expected.
Am I missing something simple here?
[TestFixture]
public class AutomapperTest
{
[Test]
public void…

Geoff
- 210
- 2
- 3
- 10
7
votes
3 answers
Compare DataRow collection to List
I have a List and I have a DataTable.
One of the columns in a DataRow is ID. The List holds instances of this ID.
The DataTable gets populated on a Timer.
I want to return items from the List that are not in the DataTable into another list.

Jon
- 38,814
- 81
- 233
- 382
7
votes
2 answers
how to search DataTable for specific record?
Hi,
I have a windows form with 10 text fields and 1 combobox.
When the user selects a record in the combo-box I want to find that record in my form datatable variable (called dtBranches) then populate my 10 textfields from the datarow.
I tried…

Our Man in Bananas
- 5,809
- 21
- 91
- 148