Questions tagged [datarow]

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

755 questions
39
votes
2 answers

How to check if Datarow value is null

Tell me please is this is correct way to check NULL in DataRow if need to return a string Convert.ToString(row["Int64_id"] ?? "") Or should be like check with DBNull.Value. Need to so much more smaller than if(row["Int64_id"] !=…
AleksP
  • 1,244
  • 2
  • 12
  • 18
31
votes
4 answers

Getting datarow values into a string?

I have a dataset called "results" with several rows of data. I'd like to get this data into a string, but I can't quite figure out how to do it. I'm using the below code: string output = ""; foreach (DataRow rows in results.Tables[0].Rows) { …
Kevin
  • 4,798
  • 19
  • 73
  • 120
31
votes
3 answers

Why can't I do foreach (var Item in DataTable.Rows)?

Is there a reason why I can't do the following: foreach (var Item in DataTable.Rows) { rather than having to do foreach (DataRow Item in DataTable.Rows) { I would have thought this was possible, like it is on other datatypes. For example: foreach…
GateKiller
  • 74,180
  • 73
  • 171
  • 204
30
votes
11 answers

How to delete multiple rows in a DataTable?

How can I delete specific DataRows within a loop of a DataTable rows which meet a custom condition -lets say the rows having an index of even number-? (Without using LINQ) Thanks
pencilCake
  • 51,323
  • 85
  • 226
  • 363
27
votes
3 answers

How to get a DataRow out the current row of a DataReader?

Ok, I would like to extract a DataRow out a DataReader. I have been looking around for quite some time and it doesn't look like there is a simple way to do this. I understand a DataReader is more a collection of rows but it only read one row at the…
Rémi
  • 3,867
  • 5
  • 28
  • 44
24
votes
12 answers

C# DataRow Empty-check

I got this: DataTable dtEntity = CreateDataTable(); drEntity = dtEntity.NewRow(); Then I add data to the row (or not). Lots of code, really don't know if there's anything inside the row. Depends on the input (i am importing from some files). I'd…
Ash
  • 1,269
  • 3
  • 25
  • 49
22
votes
2 answers

difference between getting value from DataRow

Sample code: DataTable table = new DataTable(); // ... // insert column to table table.Columns.Add("name"); // ... // insert value to table foreach (DataRow row in table.Rows) { row["name"]; …
nirmus
  • 4,913
  • 9
  • 31
  • 50
22
votes
3 answers

How to add a button to a column in the DataGridView

DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Software Title", typeof(string))); dt.Columns.Add(new DataColumn("Version", typeof(string))); dt.Columns.Add(new DataColumn("Uninstall", typeof(System.Windows.Forms.Button))); DataRow…
software is fun
  • 7,286
  • 18
  • 71
  • 129
22
votes
5 answers

How I can search rows in a datatable with a searchstring?

I want to search rows in my DataTable. I've tried this: protected void imggastsuche_Click(object sender, EventArgs e) { string searchstring = txtgastsuche.Text; DataTable tb =…
Tarasov
  • 3,625
  • 19
  • 68
  • 128
20
votes
5 answers

Why ItemContainerGenerator.ContainerFromIndex() returns null and how to avoid this behavior?

I'm using this snippet to analyze the rows I've selected on a datagrid. for (int i = 0; i < dgDetalle.Items.Count; i++) { DataGridRow row = (DataGridRow)dgDetalle.ItemContainerGenerator.ContainerFromIndex(i); FrameworkElement cellContent =…
JPCF
  • 2,232
  • 5
  • 28
  • 50
18
votes
4 answers

Use of C# var for implicit typing of System.Data.Datarow

foreach (var row in table.Rows) { DoSomethingWith(row); } Assuming that I'm working with a standard System.Data.DataTable (which has a collection of System.Data.DataRow objects), the variable 'row' above resolves as an object type, not a…
christofr
  • 2,680
  • 1
  • 18
  • 19
17
votes
4 answers

Finding null value in Dataset - DataRow.IsNull method vs ==DbNull.Value - c#

What are the benefits of using the c# method DataRow.IsNull to determine a null value over checking if the row equals DbNull.value? if(ds.Tables[0].Rows[0].IsNull("ROWNAME")) {do stuff} vs if(ds.Tables[0].Rows[0]["ROWNAME"] == DbNull.value) {do…
Jarrod
  • 1,535
  • 3
  • 16
  • 19
17
votes
5 answers

How can I convert DataRow to string Array?

I have some values in a DataGridRow (item Array) and I want to fetch all these values into a string array. How can I achieve this? DataGridRow row = (DataGridRow)Lst.ItemContainerGenerator.ContainerFromIndex(k); DataRowView Drv =…
Shashank
  • 6,117
  • 20
  • 51
  • 72
16
votes
4 answers

Setting a DataRow item to null

I have a text file that I read into a data table and then perform a bulk insert into a SQL Server table. It's quite fast and it works great when all the imported values are treated as strings (dates, strings, ints, etc are all imported into string…
DenaliHardtail
  • 27,362
  • 56
  • 154
  • 233
16
votes
4 answers

How to retrieve values from the last row in a DataTable?

I am having problems retrieving values from the last inserted row in a Data-table. I have a login form and the values will be inserted in the table has the ID (int,an auto incremented value), userID (int), logintime (smalldatetime) and…
Cindrella
  • 343
  • 3
  • 5
  • 16
1
2
3
50 51