Questions tagged [datarow]

DataRow is an ADO.Net class that represents a row of a data in a DataTable.

755 questions
131
votes
5 answers

Simple way to copy or clone a DataRow?

I'm looking for a simple way to make a clone of a DataRow. Kind of like taking a snapshot of that Row and saving it. The values of original Row are then free to change but we still have another saved copy which doesn't change. Is this the correct…
Paul Matthews
  • 2,164
  • 5
  • 20
  • 29
118
votes
5 answers

Check if DataRow exists by column name in c#?

I want to do something like this: private User PopulateUsersList(DataRow row) { Users user = new Users(); user.Id = int.Parse(row["US_ID"].ToString()); if (row["US_OTHERFRIEND"] != null) { …
waqasahmed
  • 3,555
  • 6
  • 32
  • 52
111
votes
14 answers

Simple way to convert datarow array to datatable

I want to convert a DataRow array into DataTable ... What is the simplest way to do this?
Developer404
  • 5,716
  • 16
  • 64
  • 102
110
votes
2 answers

ADO.NET DataRow - check for column existence

How do I check for the existence of a column in a datarow? I'm building datatables to organize some data that I've already pulled back from the database. Depending on the type of data in each row, I need to create a datatable with different…
Tone
  • 2,793
  • 6
  • 29
  • 42
90
votes
6 answers

How can I add a new column and data to a datatable that already contains data?

How do I add a new DataColumn to a DataTable object that already contains data? PseudoCode //call SQL helper class to get initial data DataTable dt = sql.ExecuteDataTable("sp_MyProc"); dt.Columns.Add("NewColumn",…
Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231
75
votes
5 answers

How do I get column names to print in this C# program?

I've cobbled together a C# program that takes a .csv file and writes it to a DataTable. Using this program, I can loop through each row of the DataTable and print out the information contained in the row. The console output looks like this: ---…
Kevin
  • 4,798
  • 19
  • 73
  • 120
63
votes
9 answers

DataRow: Select cell value by a given column name

I have a problem with a DataRow that I'm really struggling with. The datarow is read in from an Excel spreadsheet using an OleDbConnection. If I try to select data from the DataRow using the column name, it returns DBNull even though there is data…
VaticanUK
  • 1,127
  • 1
  • 9
  • 24
62
votes
4 answers

How to find out if a column exists in a DataRow?

I am reading an XML file into a DataSet and need to get the data out of the DataSet. Since it is a user-editable config file the fields may or may not be there. To handle missing fields well I'd like to make sure each column in the DataRow exists…
Bryan Anderson
  • 15,969
  • 8
  • 68
  • 83
53
votes
4 answers

DataColumn Name from DataRow (not DataTable)

I need to iterate the columnname and column datatype from a specific row. All of the examples I have seen have iterated an entire datatable. I want to pass a single row to a function to do a bunch of conditional processing. I want to separate the…
James Dean
  • 763
  • 1
  • 11
  • 22
52
votes
4 answers

Convert DataRowCollection to DataRow[]

What's the best performing way to convert a DataRowCollection instance to a DataRow[]?
Jeff
49
votes
4 answers

get index of DataTable column with name

I have some code which sets the value of cells in a DataRow by column name i.e. row["ColumnName"] = someValue; I want to also set the value for this row in the column immediately to the right of the one found above. Clearly if I was getting the…
Andy
  • 7,646
  • 8
  • 46
  • 69
46
votes
8 answers

Find row in datatable with specific id

I have two columns in a datatable: ID, Calls. How do I find what the value of Calls is where ID = 5? 5 could be anynumber, its just for example. Each row has a unique ID.
RSM
  • 14,540
  • 34
  • 97
  • 144
46
votes
8 answers

How to add new DataRow into DataTable?

I have a DataGridView binded to a DataTable (DataTable binded to database). I need to add a DataRow to the DataTable. I'm trying to use the following code: dataGridViewPersons.BindingContext[table].EndCurrentEdit(); DataRow row =…
malcoauri
  • 11,904
  • 28
  • 82
  • 137
41
votes
15 answers

Safely Removing DataRow In ForEach

I don't understand why this code does not work. foreach (DataRow dataRow in dataTable.Rows) { if (true) { dataRow.Delete(); } }
Jack Kada
  • 24,474
  • 29
  • 82
  • 106
40
votes
3 answers

Adding new row to datatable's top

When we use datatable.newrow command, a new empty row added to bottom of rows. However I want newrow to added to top of datatable. How can I make it?
mavera
  • 3,171
  • 7
  • 45
  • 58
1
2 3
50 51