Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


If a dataset contains 100 rows, how to fetch rows between 10
and 20 only ?

Answers were Sorted based on User's Feedback



If a dataset contains 100 rows, how to fetch rows between 10 and 20 only ?..

Answer / bhuvana

We can use DataTable.Select method to fetch rows. see the
following example:
In this
customerTable.Select( strExpr, strSort,
DataViewRowState.Added ) fetches the records which is
greater then 5.

Private Sub GetRowsByFilter()

Dim customerTable As DataTable
customerTable = new DataTable( "Customers" )

' Add columns
customerTable.Columns.Add( "id", GetType(Integer) )
customerTable.Columns.Add( "name", GetType(String) )

' Set PrimaryKey
customerTable.Columns("id").Unique = true
customerTable.PrimaryKey = new DataColumn() {
customerTable.Columns("id") }

' add ten rows
Dim id As Integer
For id = 1 To 10
customerTable.Rows.Add( _
new object() { id, string.Format("customer{0}",
id) } )
Next id
customerTable.AcceptChanges()

' add another ten rows
For id = 11 To 20
customerTable.Rows.Add( _
new object() { id, string.Format("customer{0}",
id) } )
Next id

Dim strExpr As String
Dim strSort As String

strExpr = "id > 5"
' Sort descending by CompanyName column.
strSort = "name DESC"
' Use the Select method to find all rows matching the
filter.
Dim foundRows As DataRow() = _
customerTable.Select( strExpr, strSort,
DataViewRowState.Added )

PrintRows( foundRows, "filtered rows")

foundRows = customerTable.Select()
PrintRows( foundRows, "all rows")
End Sub

Private Sub PrintRows( rows() As DataRow, label As String)
Console.WriteLine( "\n{0}", label )
If rows.Length <= 0 Then
Console.WriteLine( "no rows found" )
Exit Sub
End If
Dim r As DataRow
Dim c As DataColumn
For Each r In rows
For Each c In r.Table.Columns
Console.Write( "\t {0}", r(c) )
Next c
Console.WriteLine()
Next r
End Sub

Is This Answer Correct ?    2 Yes 3 No

If a dataset contains 100 rows, how to fetch rows between 10 and 20 only ?..

Answer / krishnareddy

USE EXECUTEPAGEREADER()

Is This Answer Correct ?    1 Yes 2 No

If a dataset contains 100 rows, how to fetch rows between 10 and 20 only ?..

Answer / ramesh

Dataset consists of DataTable collection which consists of
DataRows. Create Dataset object, then create DataRow object

Dim objRow as New DataRow

objRow(9) to objTow(19) woud give the rows between 10 and
20, as first row is stored with index

Is This Answer Correct ?    4 Yes 6 No

If a dataset contains 100 rows, how to fetch rows between 10 and 20 only ?..

Answer / anu

objRow(9) to objTow(19)

mentioned above would return the column index and would not
return the loop.

Corrrect me if I am wrong

Is This Answer Correct ?    3 Yes 5 No

Post New Answer

More ADO.NET Interview Questions

oledbdataadpter with ms access in c#.net giving exception System.Data.OleDb.OleDbException while writing adapter.update(dataset,"tabname"); how to update the database from dataset?

0 Answers   Infosys, Wipro,


how to create a quiz software using 4 options to answer and how to check with answers in the database and award marks....

1 Answers   Ford,


How xml files and be read and write using dataset ?

1 Answers  


What are the parameters that control most of connection pooling behaviors?

0 Answers  


Command objects uses, purposes and their methods.

0 Answers  


How can we save all data from dataset?

0 Answers  


Which one of the objects is a high-level abstraction of the connection and command objects in ado.net?

0 Answers  


What is the difference between Data adaptor and Data set?

0 Answers   HCL,


What is the namespaces being used to access oracle database?

0 Answers  


I want to ask u that if i add radio button in ado.net form,and how radion button data insert in SQL2005 Database...

6 Answers  


Define different execute methods of ADO.NET command object ?

0 Answers   NA,


What is the difference between Datareader and Dataset?

0 Answers  


Categories