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 DatabaseName = GetDatabaseName(); RBModule = "EXMOD"; ROName = "EmployeeList"; // open RedBack object using subroutine - "N" means treat as stateful object OpenRedbackObject(out ro, DatabaseName, RBModule, ROName, "", "", "N"); // Could Set select statement into Object Property but we are going to get all records instead myprop = (REDPAGESLib.RedProperty)ro.Property ("select_criteria"); //myprop.Value = "SELECT EMPLOYEES WITH DEPT = \"" + Id + "\" BY LAST.NAME BY FIRST.NAME"; myprop.Value = "SELECT EMPLOYEES BY LAST.NAME BY FIRST.NAME"; //Call Method rs = (ADOR.Recordset)ro.CallMethod("Select"); myprop = (REDPAGESLib.RedProperty)ro.Property ("MaxRows"); Icnt = Convert.ToInt16(myprop.Value); if (Icnt > 0) { PageTot = Convert.ToInt32(Icnt / 10); IntRem = Icnt - (PageTot * 10); if (IntRem != 0) { PageTot = PageTot + 1; } txtPageTot.Text = PageTot.ToString(); //Fill Dataset with Entire Recordset // RecordsetToDatatable(rs, ref dtblEmps); RecordsetToDatatableWithLink(rs, ref dtblEmps,"EMP.ID","uqueryex1_1.aspx?id="); //Add DataTable to DataSet dstEmps.Tables.Add(dtblEmps); //Display Datatable in Dataset DataGrid1.DataSource = dstEmps; DataGrid1.DataBind(); } ro.Close(); rs.Close(); txtPageNo.Text = PageNo.ToString(); } catch (Exception ex) { //Set Message label with error message Mess.Text = "Exception occurred: " + ex.Message; } 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.
private void RecordsetToDatatableWithLink(ADOR.Recordset rs, ref DataTable dtblEmps, string LinkFieldName, string LinkPage) { string fn; dtblEmps = new DataTable("Emps"); for(int j = 0; j < rs.Fields.Count; j++) { dcolColumn = new DataColumn(rs.Fields[j].Name.ToString(), System.Type.GetType("System.String")); dtblEmps.Columns.Add(dcolColumn); } //Add rows for (int i = 1; i <= rs.RecordCount; i++) { drowItem = dtblEmps.NewRow(); for(int j = 0; j < rs.Fields.Count; j++) { fn = rs.Fields[j].Name.ToString(); if (fn == LinkFieldName) { drowItem[fn] = "<A CLASS=bluelink HREF='" + LinkPage + rs.Fields[fn].Value.ToString() + "'>" + rs.Fields[fn].Value.ToString() + "</a>"; } else { drowItem[fn] = rs.Fields[fn].Value.ToString(); } } dtblEmps.Rows.Add(drowItem); rs.MoveNext(); } } See the rbexamplesnetcsharp directory to review the page's entire source code. |