.NETGURU
Finding the Number of a New Row
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.

Post a new message to this list...

Gregory A Greenman
If I have a table ("tbl") in a dataset ("ds") with these three
fields:

pk - autoincrement, seed = -1, step = -1
fld0
fld1

and I add a new row, how can I find its row number for the
default view?

Here's some sample code:

---------------
dim dr as datarow
dim lngIndex as long

dr = ds.tables("tbl").newrow
dr("fld0") = 100
dr("fld1") = "Hello World"
ds.tables("tbl").rows.add(dr)

lngIndex = getNumberOfTheRowIJustAdded
---------------

What do I replace "getNumberOfTheRowIJustAdded" with in order to
get the new row number if I want it for a default view?

Unfortunately, the find method returns the row itself, rather
than its number. Since I can't see any way to determine the row
number from that, it doesn't solve my problem. The only solution
I see is to iterate through the data until I have a match.

Also, am I correct in assuming that the number of the newly added
row is the same as ds.tables("tbl").rows.count - 1 if I am not
using a view?

Thanks for any help.

--
Greg
----
greg -at- spencersoft -dot- com
Reply to this message...
 
    
Miha Markic [MVP C#]
Hi Gregory,

"Gregory A Greenman" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

You should use DataView.Find() method as position in DataView is bound to
current sorting value.
Or, iterate through all DataView rows and check their Row property against
your new row).

[Original message clipped]

Yes. The row is added at the end.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Reply to this message...
 
    
Gregory A Greenman
In article <O$Click here to reveal e-mail address>, "Miha Markic
[MVP C#]" <miha at rthand com> says...
> Hi Gregory,

Hello

[Original message clipped]

Unfortunately, Dataview.Find only works if the sort is unique,
which may not be the case for my application.

[Original message clipped]

Actually, as I was lying awake suffering from insomnia, I had an
idea that seems to work. My table has another field called
"sort", which is a user editable sort field. So, when I add a new
row, I'll just make sure it sorts to the beginning. Here's some
sample code:

---------------
dim dr as datarow
dim lngIndex as long

dr = ds.tables("tbl").newrow
dr("fld0") = 100
dr("fld1") = "Hello World"

with ds.tables("tbl").defaultview
dr("sort") = iif(.count = 0, 0, .Item(0).Item("sort") -1)
end with

ds.tables("tbl").rows.add(dr)

lngIndex = 0
---------------

I've tested it and that seems to satisfy my needs. Of course,
this also means that sort is unique (for the new record), so I
could do a find, but since I know it's first, I don't need to.

Many thanks for your help. Now if you can just suggest a cure for
insomnia, you'll have solved all my problems.

--
Greg
----
greg -at- spencersoft -dot- com
Reply to this message...
 
 
System.Data.DataView




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification