PC Review


Reply
Thread Tools Rate Thread

DataTable.AddNew()

 
 
JJ
Guest
Posts: n/a
 
      9th Oct 2008
Hello NG

I have the following code:

DataTable dt = new DataTable();
..... prepare the columns.
DataRow rowNew = dt.NewRow();
....
....
DataTable.Rows.Add(rowNew);

My question, can i be sure that datatable.rows.add() method always adds to
end of rows. So that if i need to get the row again, i can simply use the
rowNew = dt.Rows[dt.Rows.Count-1];

I know that I can drill the rows to locate the rowNew.RowState = Added but
if I have more than one added row i can't use that.

Kind regards.
Johnny E. Jensen


 
Reply With Quote
 
 
 
 
Jim Rand
Guest
Posts: n/a
 
      9th Oct 2008
rowNew is simply a pointer. Hold onto that in a module level collection or
arraylist.

"JJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello NG
>
> I have the following code:
>
> DataTable dt = new DataTable();
> .... prepare the columns.
> DataRow rowNew = dt.NewRow();
> ...
> ...
> DataTable.Rows.Add(rowNew);
>
> My question, can i be sure that datatable.rows.add() method always adds to
> end of rows. So that if i need to get the row again, i can simply use the
> rowNew = dt.Rows[dt.Rows.Count-1];
>
> I know that I can drill the rows to locate the rowNew.RowState = Added but
> if I have more than one added row i can't use that.
>
> Kind regards.
> Johnny E. Jensen
>



 
Reply With Quote
 
JJ
Guest
Posts: n/a
 
      9th Oct 2008
Eh...
That was'nt the question.
If i had the ability to just hold on to the rowNew obejct, why ask for
finding it in the datatable.rows collection?
I want to ensure that ...rows.add method i always adding row to the end of
the rows collection.

Kind regards
JJ

"Jim Rand" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> rowNew is simply a pointer. Hold onto that in a module level collection or
> arraylist.
>
> "JJ" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hello NG
>>
>> I have the following code:
>>
>> DataTable dt = new DataTable();
>> .... prepare the columns.
>> DataRow rowNew = dt.NewRow();
>> ...
>> ...
>> DataTable.Rows.Add(rowNew);
>>
>> My question, can i be sure that datatable.rows.add() method always adds
>> to end of rows. So that if i need to get the row again, i can simply use
>> the rowNew = dt.Rows[dt.Rows.Count-1];
>>
>> I know that I can drill the rows to locate the rowNew.RowState = Added
>> but if I have more than one added row i can't use that.
>>
>> Kind regards.
>> Johnny E. Jensen
>>

>
>



 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      10th Oct 2008
I think it is always added to the end of the collection.
However, if you want to be on the safe side then you should search rows
using unique key.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"JJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello NG
>
> I have the following code:
>
> DataTable dt = new DataTable();
> .... prepare the columns.
> DataRow rowNew = dt.NewRow();
> ...
> ...
> DataTable.Rows.Add(rowNew);
>
> My question, can i be sure that datatable.rows.add() method always adds to
> end of rows. So that if i need to get the row again, i can simply use the
> rowNew = dt.Rows[dt.Rows.Count-1];
>
> I know that I can drill the rows to locate the rowNew.RowState = Added but
> if I have more than one added row i can't use that.
>
> Kind regards.
> Johnny E. Jensen
>


 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      12th Oct 2008
It always adds to the end. But, be carefull that when you go to get that
"last row", that another row hasn't been added in the interim.

"JJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello NG
>
> I have the following code:
>
> DataTable dt = new DataTable();
> .... prepare the columns.
> DataRow rowNew = dt.NewRow();
> ...
> ...
> DataTable.Rows.Add(rowNew);
>
> My question, can i be sure that datatable.rows.add() method always adds to
> end of rows. So that if i need to get the row again, i can simply use the
> rowNew = dt.Rows[dt.Rows.Count-1];
>
> I know that I can drill the rows to locate the rowNew.RowState = Added but
> if I have more than one added row i can't use that.
>
> Kind regards.
> Johnny E. Jensen
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# insertion of a record with CurrencyManager AddNew() method during the insertion of a father table record (with CurrencyManager AddNew() too) polocar Microsoft C# .NET 0 27th Sep 2006 06:51 PM
DataTable -> DataView -> Sort -> DataGrid : need related DataTable index Diamonds Microsoft ADO .NET 4 28th Jun 2006 08:23 PM
what is the best way to make a DataTable thread safe? DataTable.AcceptChanges() will throw exception (not documented) Ryan Liu Microsoft C# .NET 3 7th Jun 2006 05:07 PM
Retrieving datarows using DataTable.Select method and adding it to new DataTable C.Anand via DotNetMonster.com Microsoft ADO .NET 4 4th Apr 2005 05:21 PM
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select Dan V. Microsoft C# .NET 3 1st Jul 2004 03:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:16 PM.