Passing a Dataset from a function in a class

D

Daren Hawes

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("@Job_Title_ID",
System.Data.SqlDbType.Int, 4)).Value = Job_Title_ID
SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@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
 
L

Lucas Tam

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top