473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

index number of a datarow in a data table

TB
Hi All:

Here´s a very simple question:

I have created a datatable inside a dataset, and subsequently selected
a particular row using certain criteria. How do get the index number of
that particular row? There doesn´t seem to be property like
"mydatable.curr entlyselectedro windex" or "myrow.indexnum ber".

Any suggestions will be highly appreciated.

TB

Jan 15 '06 #1
6 5693
You probably should not build a program that depends on the row index.

There is not an index property for the DataRow because a program does not
usually depend on an index that would change every time the collection is
resorted or re-filtered. If, for whatever reason, you have to get the row
index you might have to iterate through the rows collection till you find the
a row that equals the row you have selected, for example:

Dim foundRow As DataRow
' Create an array for the key values to find.
Dim findTheseVals(2 ) As Object
' Set the values of the keys to find
findTheseVals(0 ) = "John"
findTheseVals(1 ) = "Smith"
findTheseVals(2 ) = "5 Main St."
foundRow = myTable.Rows.Fi nd(findTheseVal s)
Dim i As Integer
Dim iRowIndex As Integer
For i = 0 To myTable.Rows.Co unt - 1
If myTable.Rows(i) .Equals(foundRo w) Then
iRowIndex = i
Exit For
End If
Next

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

"TB" wrote:
Hi All:

Here´s a very simple question:

I have created a datatable inside a dataset, and subsequently selected
a particular row using certain criteria. How do get the index number of
that particular row? There doesn´t seem to be property like
"mydatable.curr entlyselectedro windex" or "myrow.indexnum ber".

Any suggestions will be highly appreciated.

TB

Jan 15 '06 #2
TB
Thanks for replying so fast.

You see, my requirements are the following:

I need to create a page which has two functions: 1) display the content
a specific record in a database table and 2) page forward and backward
from the initial specific record mentioned before.

When the page loads, a datatable ("mydatatabl e") is created, and a
specific record is selected according certain criteria. Furthermore,
the page contains "Next" and "Previous" buttons, which allows for the
user to move forward and backwards in the datatable, but always using
the initially selected record as a starting point.

My idea is therefore to identify the initially selected record by its
index number, from which one can more up and down by adding to or
subtracting from that initial value (the minimum value being 0 and the
maximum value being mydatatable.row s.count - 1)

Let me know what you think.

Thanks

TB

Jan 15 '06 #3
You might be able to avoid searching for the row index if you bind the data
to server controls (which have index for selected records).

http://www.webswapp.com/CodeSamples/...FormView2.aspx

I put at this link a demo where I bound a dropdownlist and a FormView to do
the function that you are trying to do without writing codebehind to search
for the row index.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"TB" wrote:
Thanks for replying so fast.

You see, my requirements are the following:

I need to create a page which has two functions: 1) display the content
a specific record in a database table and 2) page forward and backward
from the initial specific record mentioned before.

When the page loads, a datatable ("mydatatabl e") is created, and a
specific record is selected according certain criteria. Furthermore,
the page contains "Next" and "Previous" buttons, which allows for the
user to move forward and backwards in the datatable, but always using
the initially selected record as a starting point.

My idea is therefore to identify the initially selected record by its
index number, from which one can more up and down by adding to or
subtracting from that initial value (the minimum value being 0 and the
maximum value being mydatatable.row s.count - 1)

Let me know what you think.

Thanks

TB

Jan 16 '06 #4
TB
You seem to use ASP.NET 2.0 for your demo. Since I am still in the 1.1x
world, I wonder whether your example will work. Furthermore, I "only"
understand VB.NET, and not C#.

Please bear with me.....

TB

Jan 16 '06 #5
In ver#1.1, you can use a datagrid with PageSize=1 to get the equivalent of a
FormView. The rest is the same. Here is a demo in VB:
http://www.societopia.net/samples/record_select.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"TB" wrote:
You seem to use ASP.NET 2.0 for your demo. Since I am still in the 1.1x
world, I wonder whether your example will work. Furthermore, I "only"
understand VB.NET, and not C#.

Please bear with me.....

TB

Jan 16 '06 #6
TB
Thanks a lot for your insight.

Going back to your initial proposal, I wondered if it could simplified
a bit, because it seems like it runs through the entire mytable twice
(first at the "mytable.Rows.F ind(findtheseva ls) and later in the
For.....Next loop. How about something like this (in this case inside a
page_load sub):

Dim foundRow As DataRow
Dim irecord as integer
Dim i As Integer
Dim iRowIndex As Integer

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then 'The first time the page is accessed
Session("irecor d") = Request.QuerySt ring("id") 'Just for the sake of
this example
For i = 0 To myTable.Rows.Co unt - 1
If myTable.Rows(i) .item("ID") = irecord Then
foundrow = mytable.rows(i)
iRowIndex = i
Session("iRowIn dex") = irowIndex
Exit For
End If
Next i
Else
irecord = Session("irecor d")

End If
filltable() 'referrring to a sub where the table is populated
with foundrow content
End Sub

On the page there could be two buttons for navigating back and forward.
This would be the associated code:

Private Sub btnPrevious_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPrevious.Cli ck
if irowIndex <> 0 then
Session("irowIn dex") = Session("irowIn dex") - 1
foundrow = mytable.Rows(Se ssion("irowInde x"))
filltable()
end sub

Private Sub btnNext_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPrevious.Cli ck
if irowIndex <> (mytable.Rows.C ount - 1) then
Session("irowIn dex") = Session("irowIn dex") + 1
foundrow = mytable.Rows(Se ssion("irowInde x"))
filltable()
end sub
Please let me know what you think.

Jan 17 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
5416
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB 7.2 environment, the choices the optimizer makes often seem flaky. But this last example really floored me. I was hoping someone could explain why I get worse response time when the optimizer uses two indexes, than when it uses one. Some context:
11
27432
by: Tim Frawley | last post by:
I need to return a DataRow or the Row Index in a DataSet wherein the value I am attempting to find is not a primary key. I have to do this often, more than 200 times when importing a file so it needs to be fast. Could I use a Dataview to filter for the value (which is unique) and return either the DataRow object so I can modify it and put it back into the DataSet the view is based on or somehow get the RowIndex in the DataSet that the...
1
1419
by: Cordine | last post by:
i have the data row object & the data table object. I want to determine what the index position of this datarow object is in the containing table. How can i determine this??? i.e, using the row index number i can get hold of the row object DIM oRow as DataRow = oDataTable.Rows(nIndex)
0
4804
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having manually inserted a row in the table bound to the Combo box. The InsertAt Method of adding a row just does not work. Hope this helps anyone with this problem. john
4
4543
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
3
8800
by: Programatix | last post by:
Hi. I'm using a strongly typed dataset and I would like to get the index number of a column from a datarow. Is that possible? I would like to avoid using expression like this, myTable.Columns.IndexOf("myColumnName") Thanks.
0
2146
by: dalaeth | last post by:
I have searched Google high and low and haven't found anything that works. Here's my problem, hopefully someone will be able to help! I'm using 1.1 Framework, and ODP.NET 9.5.0.7 on a Windows 2003 Server. I have a cached DataSet that I fill using an OracleDataAdapter. Changes are made to that dataset in memory and as rows are changed, they are updated back to the database using OracleDataAdapter.Update(DataRow). Every few minutes, I...
8
2276
by: Joe Rattz | last post by:
Ok, I can't believe what I am seeing. I am sure I do this other places with no problems, but I sure can't here. I have some code that is indexing into the ItemArray in a DataSet's DataRow. I basically want to change the value of the data stored at a particular index in the ItemArray. Ideally, I would like for my code to look like this (pay attention to the index of ItemArray): row.ItemArray = itemArray.ToString().Substring(3);
2
15074
by: clogg02 | last post by:
Hi, I have bound a DataView to a DataGridView using this.dataGridView1.DataSource = new DataView(this.dataTable1); I allow for sorting of the datagridview using clicks on the headers. Later on I need to determine the content of any selected cell or row in that datagridview once a button has been pressed.
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.