If a dataset contains 100 rows, how to fetch rows between 10
and 20 only ?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Explain how to bind the controls(best practice) comboboxes to the data in the dataset?
What is difference between ado and other data object?
differences between ADO and ADO.NET
What is the difference between SqlCommand and SqlCommandBuilder?
What is the difference in record set and dataset?
Difference between datareader and dataset?
26 Answers Microsoft, Noel Infotech, Satyam, Value Labs,
What property must be set and what method must be called in your code to bind the data from some data source to the Repeater control?
What is dbcontext and dbset in entity framework?
Explain the advantages and disadvantages of using datalist?
Define the data provider classes that is supported by ado.net?
What is adodb dll?
What is the role of the dataset object in ado.net?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)