Wednesday, March 21, 2012

Passing a Dataset from a function in a class

Hi, I have a class called Jobs. In that class is the function below..
Public Function GetJobTitle(ByVal Job_Title_ID As Integer, ByVal Company_ID
As Integer) As DataSet
' Setup the Stored Procedure
Dim SqlCommand As New SqlCommand
Dim SqlConnection As New SqlConnection(DataLayer.ConnectionString)
Try
SqlCommand.CommandText = "dbo.DeleteJobTitle"
SqlCommand.CommandType = System.Data.CommandType.StoredProcedure
SqlCommand.Connection = SqlConnection
' Load the Parameters
SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(0, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@dotnet.itags.org.Job_Title_ID",
System.Data.SqlDbType.Int, 4)).Value = Job_Title_ID
SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@dotnet.itags.org.Company_ID", System.Data.SqlDbType.Int,
4)).Value = Company_ID
' Fire the Procedure
SqlConnection.Open()
' Create a dataset
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = SqlCommand
Dim ds As New DataSet
da.Fill(ds, "JobTitle")
Return ds
Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
SqlConnection.Close()
End Try
End Function
I now have a web form called Default.aspx
How can I poplulate a Datagrid or Select box from the above function?
Datagrid1.Datasource = jobs.GetJobTitle(1,1) ?
Please help
Thanks Daren"Daren Hawes" <newsgroups@.webdesignmagic.com.au> wrote in
news:uOXyu5cVFHA.1452@.TK2MSFTNGP14.phx.gbl:

> I now have a web form called Default.aspx
> How can I poplulate a Datagrid or Select box from the above function?
> Datagrid1.Datasource = jobs.GetJobTitle(1,1) ?
Yes exactly - but just remember to call Datagrid1.databind.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]

0 comments:

Post a Comment