dataset access

D

douglas

I would like to know how to access the last row in a dataset using the
following
logic. (*Note: the line of code that says 'do something is where I want to
access the last row in the dataset. )
**Note I am using visual basic.net 2005 professional version at work
dim da As New SqlDataAdapter
Dim ds As New DataSet()
da = New SqlDataAdapter(sqlCmd)
sqlCmd.Connection = New SqlConnection(connectionString)
sqlCnn.Open()
da = New SqlDataAdapter(sqlCmd)
sqlCmd.CommandText = sqlCmd.CommandType = CommandType.StoredProcedure
da.Fill(ds)

strholdnumber = 'gets a value
Dim IntTotalRows As Integer = ds.Tables(0).Rows.Count
Dim intFileRows As Integer = UBound(aryFi)
For A = 0 To ds.Tables(0).Rows.Count - 1
For intCntr = 0 To UBound(aryFi) Step 1
If Trim(strholdnumber) = Case(Mid(aryFi(intCntr).Name, 12,5 ))
'do something
End If

Next intCntr
next

the line of code that says: For A = 0 To ds.Tables(0).Rows.Count - 1
,keeps me from accessing the last line.

Thanks!
 
M

Mr. Arnold

douglas said:
I would like to know how to access the last row in a dataset using the
following
logic. (*Note: the line of code that says 'do something is where I want to
access the last row in the dataset. )
**Note I am using visual basic.net 2005 professional version at work
dim da As New SqlDataAdapter
Dim ds As New DataSet()
da = New SqlDataAdapter(sqlCmd)
sqlCmd.Connection = New SqlConnection(connectionString)
sqlCnn.Open()
da = New SqlDataAdapter(sqlCmd)
sqlCmd.CommandText = sqlCmd.CommandType = CommandType.StoredProcedure
da.Fill(ds)

strholdnumber = 'gets a value
Dim IntTotalRows As Integer = ds.Tables(0).Rows.Count
Dim intFileRows As Integer = UBound(aryFi)
For A = 0 To ds.Tables(0).Rows.Count - 1
For intCntr = 0 To UBound(aryFi) Step 1
If Trim(strholdnumber) = Case(Mid(aryFi(intCntr).Name, 12,5 ))
'do something
End If

Next intCntr
next

the line of code that says: For A = 0 To ds.Tables(0).Rows.Count - 1
,keeps me from accessing the last line.

dim lastrow as int = ds.Tables(0).Rows.Count
ds.Tables(0).Rows(lastrow)



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4458 (20090925) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
C

Cor Ligthert[MVP]

Be aware that a dataset is only a wrapper around datatable and datarelations

You are talking about datatables. where the last row is forever

dt.Rows(dt.Rows.Count-1)

Success

Cor
 
F

Family Tree Mike

Mr. Arnold said:
dim lastrow as int = ds.Tables(0).Rows.Count
ds.Tables(0).Rows(lastrow)



__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4458 (20090925) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

That should be "off by one", right? Subtract 1 from last row.
 
M

Mr. Arnold

I don't even use DS(s) and DT(s) anymore. I guess it shows.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4459 (20090926) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top