Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Returning DataSets...


Message #1 by "LeMay, Al" <All@n...> on Fri, 23 Mar 2001 11:58:33 -0800
All



I have a function that I want to return a dataset.  I am not sure that I am

doing this correctly.  I can connect and execute the stored procedure, but I

am uncertain on how to return it to the dataset which called it from out

side.  I think it is working, but I do not know.  This is becuase I am

trying to put the results into a control, say like the DataGrid.



Now the DataGrid.Datasource is set to what?  If I can just get this piece

then I can set the DataValue and DataBind to fill out the control.



Thanks for any help.



Al LeMay

Internet Commerce & Communications

Quality Assurance

al.lemay@n...

xxx.xxx.xxxx





Message #2 by "Daniel Anderson" <dcanderson@u...> on Fri, 23 Mar 2001 13:11:59 -0700
Assuming you have a DataSet name DS that contains your resulting recordset,

you would use the following:



DataGrid.SetDataBinding(DS, "MyData")





For more info, see this link :

http://msdn.microsoft.com/library/dotnet/cpguide/cpconbindingwindowsformsdat

agridcontroltoadonetdatasets.htm



----- Original Message -----

From: "LeMay, Al" <All@n...>

To: "ASP+" <aspx@p...>

Sent: Friday, March 23, 2001 12:58 PM

Subject: [aspx] Returning DataSets...





> All

>

> I have a function that I want to return a dataset.  I am not sure that I

am

> doing this correctly.  I can connect and execute the stored procedure, but

I

> am uncertain on how to return it to the dataset which called it from out

> side.  I think it is working, but I do not know.  This is becuase I am

> trying to put the results into a control, say like the DataGrid.

>

> Now the DataGrid.Datasource is set to what?  If I can just get this piece

> then I can set the DataValue and DataBind to fill out the control.

>

> Thanks for any help.

>

> Al LeMay

> Internet Commerce & Communications

> Quality Assurance

> al.lemay@n...

> xxx.xxx.xxxx



Message #3 by Ron0079@a... on Fri, 23 Mar 2001 18:38:20 EST
In a message dated 3/23/2001 3:05:33 PM Eastern Standard Time, 

All@n... writes:



<< I have a function that I want to return a dataset. >>



Heres a class with a function in a code behind .vb file to return a list of 

employees from Northwind using stored procedure.



Public Class EmployeesDB : Inherits Page

Public Function GetEmployees() As DataSet

             Dim dataConn As New SQLConnection("server=....)

            Dim dataCmd As New ADODataSetCommand("GetEmployees", dataConn)

            dataCmd.CommandType=CommandType.StoredProcedure

            Dim ds As DataSet = New DataSet()

            

            dataCmd.FillDataSet(ds, "Table")

            

            Return ds

            

End Function

End Class



heres the function being called from the Page_Load sub routine of an .aspx 

file



Sub Page_Load(Sender As Object, E As EventArgs)

    Dim employees As New EmployeesDB()



    Dim ds As DataSet = employees.GetEmployees()



    myDataGrid.DataSource = ds.Tables(0).DefaultView()

    myDataGrid.DataBind

End Sub

--body of html file--

<asp:DataGrid id="myDataGrid" runat="server" />



I highly recommended looking at source code files for IBuySpy ecommerce 

storefront ProductsDB.



ron

Message #4 by "LeMay, Al" <All@n...> on Mon, 26 Mar 2001 13:12:00 -0800
All



Thanks for the help.  I do have a follow on question in that when you leave

you function you are not setting the Conn.Close() or the Dataset=Nothing.



Now when you call the function again, would you not get an error stating a

NULL reference?  Or is it treated differently if I place this function call

outside the ASPX file in a class and import it?



Thanks.



-----Original Message-----

From: Ron0079@a... [mailto:Ron0079@a...]

Sent: Friday, March 23, 2001 3:38 PM

To: ASP+

Subject: [aspx] Re: Returning DataSets...





In a message dated 3/23/2001 3:05:33 PM Eastern Standard Time, 

All@n... writes:



<< I have a function that I want to return a dataset. >>



Heres a class with a function in a code behind .vb file to return a list of 

employees from Northwind using stored procedure.



Public Class EmployeesDB : Inherits Page

Public Function GetEmployees() As DataSet

             Dim dataConn As New SQLConnection("server=....)

            Dim dataCmd As New ADODataSetCommand("GetEmployees", dataConn)

            dataCmd.CommandType=CommandType.StoredProcedure

            Dim ds As DataSet = New DataSet()

            

            dataCmd.FillDataSet(ds, "Table")

            

            Return ds

            

End Function

End Class



heres the function being called from the Page_Load sub routine of an .aspx 

file



Sub Page_Load(Sender As Object, E As EventArgs)

    Dim employees As New EmployeesDB()



    Dim ds As DataSet = employees.GetEmployees()



    myDataGrid.DataSource = ds.Tables(0).DefaultView()

    myDataGrid.DataBind

End Sub

--body of html file--

<asp:DataGrid id="myDataGrid" runat="server" />



I highly recommended looking at source code files for IBuySpy ecommerce 

storefront ProductsDB.



ron


  Return to Index