Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameters to VB Class

Status
Not open for further replies.

ChasBoots

MIS
Jul 23, 2002
24
US
I am using the following code as per Microsoft to convert a Dataset to XML for use in a Chartspace:

Code:
Imports System.Web
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Data
Imports System.Data.SqlClient

Public Class MakeData
    Implements IHttpHandler

    Public ReadOnly Property IsReusable() As Boolean _
    Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As HttpContext) _
    Implements IHttpHandler.ProcessRequest
        Dim sConn As String = [red]"User ID=<username>;Password=<password>;Initial Catalog=Northwind;Data Source=YourSQLServer;"[/red]
        Dim sSQL As String = _
            [red]"SELECT LastName, Sum([UnitPrice]*[Quantity]*(1-[Discount])) AS OrderTotal " & _
            "FROM Employees INNER JOIN (Orders INNER JOIN [Order Details] ON " & _
            "Orders.OrderID = [Order Details].OrderID) ON Employees.EmployeeID = " & _
            "Orders.EmployeeID GROUP BY LastName"[/red]

        'Connect to the data source.
        Dim nwindConn As SqlConnection = New SqlConnection(sConn)
        nwindConn.Open()

        'Build a dataSet for Employee Sales.
        Dim ds As DataSet
        ds = New DataSet("MyDataset")
        Dim da As SqlDataAdapter = New SqlDataAdapter(sSQL, nwindConn)
        da.Fill(ds)

        'Transform the dataSet using the stylesheet.
        Dim xmlDoc_ds As XmlDataDocument = New XmlDataDocument(ds)
        Dim xslTran As XslTransform = New XslTransform()
        xslTran.Load(context.Server.MapPath("Rowset.xslt"))

        'Return the persisted recordset.
        context.Response.ContentType = "text/xml"
        context.Response.Charset = ""
        xslTran.Transform(xmlDoc_ds, Nothing, context.Response.Output)

    End Sub

End Class

What I want to do is replace the code in red with a connection string and SQL command that is passed from the page designed to call the class. What am I missing that is likely to be obvious? Thanks...
 
Not quite sure what you are asking. Do you want to know how to create a class that encapsulates your Database calls?
 
I guess the thoughts were too specific in my head and not sufficient in my question... :(

I have a web form (Page1.aspx) that will run 1 of 5 queries against an SQL database based on user input. The results of the query are presented in a dataset. An available button can transfer the user to another page (Page2.aspx) from which a graph can be generated from the dataset.

The SQL and connection strings are URLEncoded to Page2.aspx and retrieved via Request.QueryString statements. On Page_Load, the dataset is regenerated from these strings.

During the processing of Page2.aspx, I wish to use the MakeData class to transform the dataset to an XML datasource for the purpose of binding it to a Chartspace or PivotTable object from OWC11. For reference purposes, please refer to
Unfortunately, the connection and command text strings in the example are unusable for my purposes. I want to use the parameters passed initially from Page1.aspx to generate the XML data.

So that brings me to my question. How do I pass the connection and command text strings received in Page2.aspx to MakeData?

(I hope that wasn't too confusing or too much to follow...)
 
You simply create two new properties (one for your SQL and one for your connection string). Then, before you call the ProcessRequest method, simply set those properties from your page and have your method use the properties.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Bingo! Thanks for the input. Took me a while to get implement but at least I've gotten through that part of it (other headaches follow). One of these days I will be able to take a class on .NET and learn it properly instead of having to rely on the generous help of everyone else!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top