First write an SP!. Your SP should look like this:
CREATE PROCEDURE [dbo].[sp_Retrieve_EmployeesData]
(
@GroupID int
)
AS
SELECT [Group].[GroupID], [Role].[RoleID], [Role].[RoleName] FROM [Group]
WHERE GroupID = @GroupID
RETURN
GO
Note:sp_Retrieve_EmployeesData is the dummy Stored Procedure name that i have used...and replace the SELECT query inside that with your actual one. Also, note that the stored procedure takes the GroupID as input parameter. Replace it with your own, or remove it if you don't need it.
Second, write a function that talks to the database, executes the stored procedure, returns you the result.
Public Shared Function RetrieveEmployeesData(ByVal groupID As Integer) As DataSet
Dim myConn As New SqlConnection = New SqlConnection('Place your connection string here.')
Dim myCmd As New SqlCommand
Dim spname As String = "sp_Retrieve_EmployeesData"
Dim ds As DataSet = New DataSet()
Try
myConn.ConnectionString =
myConn.Open()
myCmd.Connection = myConn
myCmd.CommandType = CommandType.StoredProcedure
myCmd.CommandText = spname
myCmd.Parameters.Add("@GroupID ", SqlDbType.Int)
myCmd.Parameters("@GroupID ").Direction = ParameterDirection.Input
Dim myDA As New SqlDataAdapter(myCmd)
myDA.Fill(ds, spname)
Catch ex As Exception
'Handle the error.
Finally
myConn.Close()
End Try
Return ds
End Function
Note the usage of the stored procedure name, and the input parameter. If you get that right, then all this is pretty easy.
Hope this helps.