Does anyone knows how can I work with a Dataset created by an SQL
procedure with an Inner Join that returns data from 2 related tables?
I need to get the data from that dataset and add it to classes.
I'm sure there are better ways to do this, but here is a sample:
sub Page_Load(sender as object, e as eventargs) handles mybase.load
dim MyDataSet = RunSQLProc(Param1Value, Param2Value)
MyDataGrid.DataSource = MyDataSet.Tables(0)
MyDataGrid.DataBind()
'If your SQL procedure returns multiple result sets, you can assign
each result set to its own datagrid:
'MyDataGrid.Tables(1), MyDataGrid.Tables (2), etc.
end sub
function RunSQLProc(ByVal Param1Value As String, ByVal Param2Value As
Date) As DataSet
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(MyConnectionString)
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = "MyStoredProcedureName"
dbCommand.CommandType = CommandType.StoredProcedure
dbCommand.Connection = dbConnection
Dim param_1 As IDataParameter = New SqlParameter
param_1.DbType = DbType.String
param_1.ParameterName = "@Param1"
param_1.Value = Param1Value
dbCommand.Parameters.Add(param_1)
Dim param_2As IDataParameter = New SqlParameter
param_2.DbType = DbType.Date
param_2.ParameterName = "@Param2"
param_2.Value = Param2Value
dbCommand.Parameters.Add(param_2)
dbConnection.Open()
Dim DA As SqlDataAdapter = New SqlDataAdapter(dbCommand)
RunSQLProc = New DataSet
DA.Fill(RunSQLProc)
dbConnection.Close()
End Function
HTH,
-E