Tornado Class Library

Special Topic - DataSet

Tornado works with Datasets closely and use it as a channel between the VS controls and Tornado's special filtering and processing. The first example is to return a simple dress-up grid as dataset.

 

Example 1: Simple SQL - DS mapping

 Use VB.Net - Drop a Datagrid to the Designer with DataGrid1 and place the following code in a WebForm.

<script language='vb' runat='server'>
Sub Page_Load(Source as Object, E as EventArgs)
  Dim DS As New Tornado.z
    With DS
      .dbQP = "U=99|S=2|Ps=-1|D=Nwind"
      .dbTextHolder = "Title=ASPdb DataGrid demo"
      .dbSQL = "Select ProductID, ProductName, UnitPrice From products"
      DataGrid1.DataSource = .ASPdbDS()
      DataGrid1.DataBind()
    End With
End Sub
</script>

 

Example 2: Standalone and two parts DS application

Sandalone aspx application delivers the application in one file instead of separating the data and code in two files. You can copy the <asp>..</asp> code to the data part if you need to.

<%@ Import Namespace="System.Data" %>
<script language="vb" runat="server">

Sub frank_Page(Sender As Object, E As DataGridPageChangedEventArgs)
  frank.CurrentPageIndex = e.NewPageIndex
  frank.DataBind()
End Sub

Sub Page_Load(Source as Object, E as EventArgs)
dim ds as new dataset()
Dim TT As New Tornado.Z()
  With TT
    .dbQP="U=99|S=2|Ps=-1"
    .dbTextHolder="Title=ASPdb DataGrid demo|Sub=Sub Title"
    .dbDSN = "nwind.mdb"
    .dbSQL = "Select ProductID, ProductName, UnitPrice From products"
    frank.DataSource = .ASPdbDS()
    frank.DataBind()
  End With'...Use DataGrid with Tornado.
End Sub
</script>

<body><center>
<form runat="server">
<asp:DataGrid id="frank" runat="server"
    CssClass="R1"
    PageSize="5"
    OnPageIndexChanged="frank_Page"
    AllowPaging="True"
    AutoGenerateColumns="True">
    <HeaderStyle HorizontalAlign="Center" CssClass="GH"></HeaderStyle>
    <AlternatingItemStyle CssClass="R2"></AlternatingItemStyle>
    <PagerStyle mode="NumericPages" horizontalalign="Left" CssClass="CC1"></PagerStyle>
</asp:datagrid>
</form></center>
</body>

 

Example 3: Standalone and two parts DS application using XML Datasource

Sandalone aspx application delivers the application in one file instead of separating the data and code in two files. You can copy the <asp>..</asp> code to the data part if you need to.

<%@ Import Namespace="System.Data" %>
<script language="vb" runat="server">

Sub frank_Page(Sender As Object, E As DataGridPageChangedEventArgs)
  frank.CurrentPageIndex = e.NewPageIndex
  frank.DataBind()
End Sub

Sub Page_Load(Source as Object, E as EventArgs)
dim ds as new dataset()
Dim TT As New Tornado.Z()
  With TT
    .dbQP="U=99|S=2|Ps=-1"
    .dbTextHolder="Title=ASPdb XML DataGrid demo"
    frank.DataSource = .ASPdbDS("XML=/tornado/db/inventory.xml")
    frank.DataBind()
  End With '...Use DataGrid and XML with Tornado.
End Sub
</script>

<body><center>
<form runat="server">
<asp:DataGrid id="frank" runat="server"
CssClass="R1"
PageSize="5"
OnPageIndexChanged="frank_Page"
AllowPaging="True"
AutoGenerateColumns="True">
<HeaderStyle HorizontalAlign="Center" CssClass="GH"></HeaderStyle>
<AlternatingItemStyle CssClass="R2"></AlternatingItemStyle>
<PagerStyle mode="NumericPages" horizontalalign="Left" CssClass="CC1"></PagerStyle>
</asp:datagrid>
</form></center>
</body>

 

Example 4: Simple StoredProcedure - DS mapping

Setup your SQL data source using the simple dbDSN or in dbQP as 'D=server;database;uid;pwd'. We'll use the standard SP example reptq2 which has 17 result sets.

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim dts As New Tornado.z
    With dts
      .dbQP = "U=99|S=2|Ps=-1|D=fujitsu;pubs;sa;sa|dt=SQL|pv=SQLClient"
      .dbTextHolder = "Title=ASPdb DataGrid SP demo|Sub=Sub Title"
      .dbStoredProc = "spname= reptq2"
      Dim DS As New DataSet
      DS = .ASPdbSP2DS()
      '...find out how many tables are there
      Dim tbs As Integer = DS.Tables.Count
      '...process tables 0 to tbs-1 your way, here just show table(1)
      DataGrid1.DataSource = DS.Tables(1)
      DataGrid1.DataBind()
    End With
End Sub

 

DataSet Data Type

Dim DSvar as DatSet = Obj.ASPdbDS("New_Field_Types")

This overload method process the connection and SQL and returns a dataset. Use can take this dataset and process with Web controls. MagicCell, LookUp and relevant Filters are supported.

Optional_New_Field_Types - This property lists the fields with their data Type changed because of the Transformation. Format is Field=FieldName_Or_Number| Type=DataType, Field=FieldName_Or_Number| Type=DataType.

Field type = string, integer, short, long, date or float.

When the RecordSet is transferred from ASP-db to The DataSet, the schema is also transferred. When data is transformed, then the data type needs to be changed. For example, EmployeeID type is is System.Int32. After the MagicCell transform, it becomes the First_Last_Name, the type now is System.String instead. You must specify the new data type. The syntax will be - Dim DSvar as DatSet = Obj.ASPdbDS("field=Employeeid| Type=String).

Now with this transformation, you can sort and filter the transformed fields in the Dataset / datagrid environment. See the example below. You'll notice that this example cannot be duplicated (easily) by using DotNet alone.

Note: If the datatype is changed then Editing is not possible with the Dataset. You must use a separate page to perform editing.

See The Magic ASPdbDS example in  Special Topic - Using Tornado with Visual Studio.Net.


Send comments on this topic.


Copyright 1998-2006 ASP-db