Data Access Layer - loop while

Hello folks, I've a little problem.
I've some code using sqldatareader and I want to replace everything for objectdatasource

In resume I want to know how to implement a WHILE in datasets statments. Right now my DAL code access only to one row and I want to access to all rows returned.

I want to convert this SQL CODE:

                                sql_series2 = " SELECT cantidad FROM carrito_tem WHERE (LibroSerie = '@LibroSerie') AND  IdUsuarios=@idpedido"
                                cmd2.CommandText = sql_series2
                                cmd2.Parameters.Add("@LibroSerie", SqlDbType.NVarChar, 250)
                                cmd2.Parameters("@LibroSerie").Value = promo1Collection
                                cmd2.Parameters.Add("@idPedido", SqlDbType.NVarChar, 50)
                                cmd2.Parameters("@idPedido").Value = Session("Usuario")

                                cmd2.Connection = con2
                                Dim rdr3 As SqlDataReader = cmd2.ExecuteReader()
                                While rdr3.Read()
                                    Response.Write(rdr3("cantidad").ToString)

                                End If
                                rdr3.Close()

TO SOMETHING LIKE THIS

                sql_series2 = New DataSetTableAdapterssql_series2
                Dim sql_series2_data As DataSet.sql_series2DataTable = sql_series2.GetById(IdUsuarios,LibroSerie )

                If sql_series2_data.Count > 0 Then
                    response.write(sql_series2_data(0).dEmId.ToString())
                End If

THANKS FOR ANY HELP
LVL 5
nkoriginalAsked:
Who is Participating?
 
nkoriginalConnect With a Mentor Author Commented:
The answer to my question is
This is an example.

Dim productsAdapter As New NorthwindTableAdapters.ProductsTableAdapter()
Dim products As Northwind.ProductsDataTable = productsAdapter.GetProducts()

For Each product As Northwind.ProductsRow In products
If Not product.Discontinued AndAlso product.UnitsInStock <= 25 Then
    product.UnitPrice *= 2
End if
Next
0
 
CodeCruiserConnect With a Mentor Commented:
Use a for loop

For i as integer = 0 to sql_series2_data.count - 1
    Response.Write(sql_series2_data.Rows(i).dEmId)
Next
0
 
KinjalKumar PatelSenior Software EngineerCommented:
Can you please let me know that you want to use ObjectDataSource or not?? Or you want to use DataSet and Datatables so that you can access any of the row without traversing through the DataReader. Will help me to answer you in a better way.
0
 
nkoriginalAuthor Commented:
Kinjal I would like to use objectdatasource.
Thanks for your hellp
0
All Courses

From novice to tech pro — start learning today.