datarow

How to delete multiple rows in a DataTable?

Hi, 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 ...

Converting datarow[] to xml. Is it possible?

I have one application, in that i am using a datarow object like this. DataRow[] drRow; drRow = _dsmenu.Tables["tblmenu"].Select("id='" + DocID + "'"); After this i make some changes in columns like this drRow[0]["Allow"] = "Yes"; after all the changes, i need to save that particular datarow as a xml to the db. I ca...

How to extend DataRow and DataTable in C# with additional properties and methods?

Hi, I would like create a custom DataRow that will have -let's say- a propery called IsCheapest. public class RateDataRow : DataRow { protected internal RateDataRow(DataRowBuilder builder) : base(builder) { } public bool IsCheapest { get; set ;} } And I want to have a new DataTable that contains only *RateDataRow*s s...

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 the second result is taken and inserted. We used to address the dataset rows directly w...

Does DataRow throw an InvalidCastException when I insert a value of a different type...?

I'm trying to catch an Exception when an invalid value gets stored into a DataRow. I'm reading the values from a text file so anything could be stored there. I was hoping to be able to catch an InvalidCastException from the following code... try { // Store the values into the Data Row DataRow row = dataset.Tables["Table"].NewRow()...

ASP.NET Conversion of DataRow[] to DataTable

How to get a DataTable from DataRow[] collection ? I tried the following conversion , but it returns null. string ProcessQuery(ref DataRow[] rows) { DataTable _tb = new DataTable(); foreach (DataRow _dr in rows) { _tb.Rows.Add(_dr); }...

vb.net loop through datarow and add each value into a listbox

Private Function ColumnEqual(ByVal A As Object, ByVal B As Object) As Boolean If A Is DBNull.Value And B Is DBNull.Value Then Return True End If If A Is DBNull.Value Or B Is DBNull.Value Then Return False End If Return A = B End Function ..... Public ...

Adding a Byte[] to a datarow

I'm trying to write a test that returns a data-reader with one of the columns being a byte[]. I figured I can create a datatable and create a reader from that. var cboTable = new DataTable("CBOTable"); var colValue = new SqlBinary(ASCII.GetBytes("Hello This is test")); cboTable.Columns.Add("ByteArrayColumn"); cboTable.Rows.Add(colValu...

Databinding a datarow on Controls in Panel

Hi, I am making a custom control based on a Panel. The main idea is to bind a datatable to this panel. There are functions for selecting a row + updating, saving and deleting this row in the custom Panel. The only problem is binding the data. I have this function: private void _addBindings() { _src = new BindingSource(...

Insert multiple rows in gridview.

Hello. I have the following code to add a new row into a datatable and then bind it to a gridview. I need to add a new row anytime i click the Button2. What do i need to change in the code so i can have multiple rows before i submit them to a database? Private Sub BindGrid() Dim DT As New DataTable Dim Row As DataRow ...

c# unable to edit datarow in dataset

I'm trying to edit the data in a dataset (change the value in a column on one row), which is not linked to a database. I've been googling for about an hour with no results and no good examples out there. Hopefully someone can help me. My table (DataTable1) has these columns - ThreadID (string, PK), StatusText (string). I can select ...

calculation between two rows of DataTable in C#

Hi. I have Datatable which has tow tables together appended. I have many rows in that two of which are Total and Rate.( Note this are the Rows in my Datatable). I want to calulalte the total amount by multiplying the two rows. How shall I do that. The datatables are coming from sql Compact and I cannot do their the calculation as it's no...

How do I populate a DataRow using DbDataRecord.GetValues?

Using VB9, I'm trying to populate a DataTable with the results from several stored procedure calls. What I'm trying to make work looks like: For Each record In New SqlCommand("exec getResults", conn).ExecuteReader Dim dr As DataRow = dt.NewRow record.GetValues(dr.ItemArray) dt.Rows.Add(dr) Next It seems like the DataRow.I...

Datagridview CellValueChanging event fires but does not update the row value.

Hi, have to work with this event: CellValueChanging, ... even when fires the row value is not updated. DataRow row = ((DataRowView)e.Column.View.GetRow(e.RowHandle)).Row; I learned that this is normal, but i need to catch in someway the data writen in the row cells. Any ideas? Thnx in advance. ...

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 = (DataRowView)row.Item; DataRow dr = (DataRow)Drv.Row; ...

DataRow which is added is not going to be delete doing table.Rows[i].Delete() ?

Why is that? The state of the datarow is added. When I delete the row the state is unchanged. Why not deleted? Thats the reason my Delete Store Procedure is never called! edit: the datarow is freshly added and then I try to delete it. ...

DataTable Concurrency Locking

I'm helping spruce up an application, and it's full of concurrency issues. I'm attempting to work through them, and came across a section that's using DataTables. The datatable itself is static, shared across many threads. I know that using dt.Select("...") itself needs a lock statement, or you'll have issues when adding/removing rows ...

Type-ing quesion

Hey everyone, I have a few tables in my database and they all contain a different inherited type of a DataRow. In addition I have a class that is supposed to handle some things in my DataGrid (My database Tables are connected to DataGrids). In order to do that, one of the methods in this DataGrid handler has to cast the rows to the exa...

C# Bind TextBox To Specific Row Of DataTable

Hello there, I am building a simple C# application that allows the user to edit the rows of a table in a database. The interface is very simple, it is basically a list of rows and a few buttons. Selecting a row and pressing the "Add" button pops up a new form with text boxes for each column. I want those columns to be populated with the...

linq to datasets - get a specific datarow

i have a table with these columns: errorCode (int) errorDesc (Varchar) i'm trying to get the datarow where errorCode is 5: DataRow resultCodeRow = (from resultCodesTableRow in resultCodesDT.AsEnumerable() where resultCodesTableRow.Field<int>("result_Code_colum_Name") == 5 ...