Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get RowID from row?

Status
Not open for further replies.

TonyScarpelli

Programmer
Jan 23, 2003
361
US
I have a search routine to get a row from a table:

gnReqID = txtSearchData.Text
Dim rowFoundRow As DataRow
Dim lnRow As Integer
rowFoundRow = objPurHeadingDS.pur_head.Rows.Find(gnReqID)

I can see a rowID column, but can't access it:

lnRow = rowFoundRow.Item("rowID") doesn't work, nor does
lnRow = rowFoundRow("rowID") nor does
lnRow = rowFoundRow(rowID)

Does anyone know how to get that rowID"

Thanks.


Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
No you can not access rowID because it is declared as Private. I might be able to help you if I you can tell the need to get the rowID. Why I am asking this because, usually when we do a Find the datarow which we just got has a direct reference to the datatable that it belongs to, so when you make any changes to the datarow, you are changing/updating the datatable and hence there is no need to keep track of the RowID to set the details back. Let me know if this helped you at all...

-Kris
 
Thanks,

Well..., what's happening is this:

I have a form with four tabs on it, the first form is for data entry and all the controls are bound to the data. This form seems to work all right.

I have another tab where the user can search for records in various fields. I can do a search and the form shows the records in a few display text controls, but when I tab back to the first data entry form the data is still showing the old record, it's not displaying the found record.

I figured I can use the rowID to position the table to the found record. But if it's there, maybe I'm not doing something when I'm moving back to the data entry tab.

Any ideas?

Thanks.


Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
Hi,

It sounds like you haven't set the relation between Tab1 and Tab2. See if you can create a DataRelation between the two Tabs. If you search in MSDN for DataRelation you will see an example of how to set the masterDetail relation. May be this is what you want to try.

-Kris
 
The two tab screens work on the same table. One finds a record and the other displays the data.

How can I set up a relationship on the same table?

Data relationships are used for two or more tables. Maybe I'm missing something here, but there's got to be something else going on. Maybe I should recreate the datasets. I'll have to work on that today.

Any other ideas?

Thanks.


Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
Tony,

Do you retrieve all data when the form loads or only when the user enters search criteria and clicks 'Find' button or so? Because if you are doing the second way defintly it has to do with databinding. If you have all the data at the form load then may be your routine which sets the data back to screen is missing something (cann't imagine what it could be).

-Kris
 
I load all the data from a SQL database into a dataset and the user sees a data entry screen with all the field controls on it. They can move through the records Top, Bottom, etc. with navigation controls and the records display correctly, so I know that works, so the binding is working there.

When I tab to the search screen I have some controls on it bound to the same dataset, and _they_ display the correct data so I know they are bound correctly.

If I search for a record, I can find the record, and the bound controls correctly change with the new found record, and that works.

But from there, when I tab back to the data entry screen, the controls only show the old record and not the new record I just searched for.

I put a bound datagrid on the search screen, and if I select a record on it, and then tab back to the data entry screen the controls show the correct data!

This is driving me nuts. :-(

Something isn't updating the data entry screen when I tab back to it, and I can't seem to find the problem.

Any other ideas?

Thanks.



Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
After going crazy for days trying to figure out why the following didn't move the table pointer...

Dim rowFoundRow As DataRow
rowFoundRow = objPurHeadingDS.pur_head.Rows.Find(lnReqNum)

even though it actually _did_ find the record, I gave up and decided on another tact to move the record pointer.

The other problem was how do I actually get a table row number from my requistion ID number. Since I couldn't figure it out directly I went indirectly and created a SQL stored procedure that got the number.

Here's the code for the stored procedure:

if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[getTempRowNum]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[getTempRowNum]
GO

CREATE PROCEDURE getTempRowNum @ReqID INTEGER
AS
Create table #RowTable
(ReqID Int, RowNum Int Identity)

Insert #RowTable(ReqID)
Select ReqID From Pur_Head
Order By ReqID

Select ReqID, RowNum
From #RowTable
Where ReqID = @ReqID
GO

This creates a temporary table that contains the requistion ID number and the row number. And then I select the req ID that I'm looking for.

The VB code that executes this follows, and assumes that the SQL Helper class is present in the project:

Private Sub GetRowNum()
Dim lnRecNum, lnRowNum As Integer
'Call ExecuteReader static method of SqlHelper class
'that returns a SqlDataReader.
'Pass in database connection string, stored procedure
'name, & value of parameter.
'Create a temp table to get the row number for the req ID
drRowNum = SqlHelper.ExecuteReader _
(gcConn, "getTempRowNum", gnReqID)
'Check to see if we found a record
If Not drRowNum.HasRows Then
gnRecNum = 0
Else
'Call Read to begin accessing the data
If drRowNum.Read() Then
lnRecNum = drRowNum.GetValue(0)
lnRowNum = drRowNum.GetValue(1)
'Row numbers start at 1, table records start at 0
gnRecNum = lnRowNum - 1
End If
End If

'Move the record pointer
myBindingManagerBase.Position = gnRecNum
Me.objdsPurHead_PositionChanged()

End Sub

This works, but it is not what I wanted to do. I just couldn't figure out why 'Find' didn't move the table's record.

If any of you ever figure this out please let me know.

CU




Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
hi TonyScarpelli,

Find function doesn't return number of row position but Object.

U can get the row by looping all the row and find the exact value that U find.

Hope that can figure out what U want.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top