This explanation assumes knowledge of ASP.NET and provides a basic RedBack example. The heart of the RedBack code goes something like this:
Try 'Make Connection to rbexamples database and Get object definition ' from Module EXMOD, object EmployeeList, passing no User, Password, and N for Stateful DatabaseName = GetDatabaseName() RBModule = "EXMOD" ROName = "EmployeeList" OpenRedbackObject(ro, DatabaseName, RBModule, ROName, "", "", "N") 'Could set select statement into Object Property, but in this example we read all records ' ro.Property("select_criteria").value = "SELECT EMPLOYEES WITH DEPT = """ & Id & """ BY LAST.NAME BY FIRST.NAME" 'Call Method to Read rs = ro.CallMethod("Select") prop = ro.Property("MaxRows") Icnt = CInt(prop.Value) txtPageNo.Text = CStr(PageNo) If Icnt > 0 Then PageTot = Int(Icnt / 10) If Icnt Mod 10 then PageTot = PageTot + 1 txtPageTot.Text = PageTot 'Fill Dataset with Entire Records 'RecordsetToDatatable(rs, dtblEmps) 'Fill Dataset with Entire Recordset with Links RecordsetToDatatableWithLink(rs, dtblEmps,"EMP.ID","uqueryex1_1.aspx?id=") 'Add DataTable to DataSet dstEmps.Tables.Add(dtblEmps) DataGrid1.DataSource = dstEmps DataGrid1.DataBind() End If ro.Close() rs.Close() Catch ex As Exception 'Set Message label with error message Mess.Text = "Exception occurred: " & ex.Message End Try The recordset is loaded into a Dataset/DataTable using the following subroutine. Note this subroutine also adds a link around the Id field, to call another page when the user clicks on the link.
Sub RecordsetToDatatableWithLink(ByVal rs, ByRef dtblEmps, LinkFieldName, LinkPage) dtblEmps = New DataTable("Emps") Dim objRSField For Each objRSField In rs.Fields dcolColumn = New DataColumn(objRSField.Name, GetType(String)) dtblEmps.Columns.Add(dcolColumn) Next 'Add rows For i = 1 To Icnt drowItem = dtblEmps.NewRow() For Each objRSField In rs.Fields If objRSField.Name = LinkFieldName Then drowItem(objRSField.Name) = "" & rs.Fields(objRSField.Name).Value & "" Else drowItem(objRSField.Name) = rs.Fields(objRSField.Name).Value End If Next dtblEmps.Rows.Add(drowItem) rs.MoveNext() Next End Sub See the rbexamplesnetvb directory to review the page's entire source code. |