Question : Load dataset from Dynamic StoredProcedure...

I want to load a dataset with data from a dynamic stored procedure (SQL server 2005) which returs a different set of columns depending on some global settings.
When i use the code below, it only returns 3 columns.
Running the some procedure in SQL returns all 11 columns.
The string-variable sql contains the name of the sp.

Any suggestions?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Dim cn As New SqlConnection(My.Settings.Conn_DB)
        cn.Open()

        Dim SqlAttr As New SqlDataAdapter
        Dim ds As New DataSet

        Dim sqlcmd As New SqlCommand
        With sqlcmd
            .Connection = cn
            .CommandType = CommandType.StoredProcedure
            .CommandText = sql
        End With

        SqlAttr.SelectCommand = sqlcmd

        Dim DtAttr As DataTable = ds.Tables.Add("Attributes")

        'Fill the Schema 
        SqlAttr.FillSchema(DtAttr, SchemaType.Mapped)

Answer : Load dataset from Dynamic StoredProcedure...

Just a correction on terminology, your not getting multiple datasets but rather multiple tables within a dataset. FillSchema shouldnt be required for filling a dataset. I would remove lines 16-19 in your coding example
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Dim cn As New SqlConnection(My.Settings.Conn_DB)
        cn.Open() 'DataAdapter will open the connection so this is not needed.

        Dim SqlAttr As New SqlDataAdapter
        Dim ds As New DataSet

        Dim sqlcmd As New SqlCommand
        With sqlcmd
            .Connection = cn
            .CommandType = CommandType.StoredProcedure
            .CommandText = sql
        End With

        SqlAttr.SelectCommand = sqlcmd
        SqlAttr.Fill(ds)
Random Solutions  
 
programming4us programming4us