The correct syntax for returning a DataSet

Discussion in 'ASP .Net' started by martinharvey via DotNetMonster.com, Oct 24, 2005.

  1. I realise this is a beginners question but i would be grateful for some help


    Untill now i have been using Datareaders for example;

    Public Class Catalog
    Public Shared Function SP_GetBB() As SqlDataReader

    ' Create the connection object
    Dim connection As New SqlConnection(ConnectionString)
    ' Create and initialize the command object
    Dim command As New SqlCommand("SP_GetBB", connection)
    command.CommandType = CommandType.StoredProcedure
    ' Open the connection
    connection.Open()
    ' Return a SqlDataReader to the calling function
    Return command.ExecuteReader(CommandBehavior.CloseConnection)
    End Function

    Can anyone tell me how to convert the above to return a Dataset
    I have got this far but am not sure how to finish:


    Public Class Catalog
    Public Shared Function SP_GetBB() As System.Data.DataSet
    ' Create the connection object
    Dim connection As New SqlConnection(ConnectionString)
    ' Create and initialize the command object
    Dim command As New SqlCommand("SP_GetBB", connection)
    command.CommandType = CommandType.StoredProcedure.........
    ....................................

    many thanks

    martin


    --
    Message posted via DotNetMonster.com
    http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200510/1
    martinharvey via DotNetMonster.com, Oct 24, 2005
    #1
    1. Advertising

  2. Hi Martin,

    you need a DataAdapter to fill your DataSet, for example:

    Public Function SelectSqlSrvRows(dataSet As DataSet, connection As String,
    query As String) As DataSet
    Dim conn As New SqlConnection(connection)
    Dim adapter As New SqlDataAdapter()
    adapter.SelectCommand = new SqlCommand(query, conn)
    adapter.Fill(dataset)
    Return dataset
    End Function

    For a description look at
    http://msdn.microsoft.com/library/d...stemdatasqlclientsqldataadapterclasstopic.asp


    Alex

    http://www.DotNet42.com - The Answer to Your DotNet question


    "martinharvey via DotNetMonster.com" wrote:

    > I realise this is a beginners question but i would be grateful for some help
    >
    >
    > Untill now i have been using Datareaders for example;
    >
    > Public Class Catalog
    > Public Shared Function SP_GetBB() As SqlDataReader
    >
    > ' Create the connection object
    > Dim connection As New SqlConnection(ConnectionString)
    > ' Create and initialize the command object
    > Dim command As New SqlCommand("SP_GetBB", connection)
    > command.CommandType = CommandType.StoredProcedure
    > ' Open the connection
    > connection.Open()
    > ' Return a SqlDataReader to the calling function
    > Return command.ExecuteReader(CommandBehavior.CloseConnection)
    > End Function
    >
    > Can anyone tell me how to convert the above to return a Dataset
    > I have got this far but am not sure how to finish:
    >
    >
    > Public Class Catalog
    > Public Shared Function SP_GetBB() As System.Data.DataSet
    > ' Create the connection object
    > Dim connection As New SqlConnection(ConnectionString)
    > ' Create and initialize the command object
    > Dim command As New SqlCommand("SP_GetBB", connection)
    > command.CommandType = CommandType.StoredProcedure.........
    > ....................................
    >
    > many thanks
    >
    > martin
    >
    >
    > --
    > Message posted via DotNetMonster.com
    > http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200510/1
    >
    =?Utf-8?B?QWxleA==?=, Oct 24, 2005
    #2
    1. Advertising

  3. Alex wrote:
    >Hi Martin,
    >
    >you need a DataAdapter to fill your DataSet, for example:
    >
    >Public Function SelectSqlSrvRows(dataSet As DataSet, connection As String,
    >query As String) As DataSet
    > Dim conn As New SqlConnection(connection)
    > Dim adapter As New SqlDataAdapter()
    > adapter.SelectCommand = new SqlCommand(query, conn)
    > adapter.Fill(dataset)
    > Return dataset
    >End Function
    >
    >For a description look at
    >http://msdn.microsoft.com/library/d...stemdatasqlclientsqldataadapterclasstopic.asp
    >
    >Alex
    >
    >http://www.DotNet42.com - The Answer to Your DotNet question
    >
    >> I realise this is a beginners question but i would be grateful for some help
    >>

    >[quoted text clipped - 29 lines]
    >>
    >> martin



    many thanks for your help with this

    Cheers

    martin


    --
    Message posted via http://www.dotnetmonster.com
    martinharvey via DotNetMonster.com, Oct 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl T
    Replies:
    4
    Views:
    449
    Jim Cheshire [MSFT]
    Oct 15, 2003
  2. joon
    Replies:
    1
    Views:
    505
    Roedy Green
    Jul 8, 2003
  3. Dan

    correct or not correct?

    Dan, Oct 2, 2003, in forum: HTML
    Replies:
    7
    Views:
    425
  4. J.Ram
    Replies:
    7
    Views:
    637
  5. froil
    Replies:
    12
    Views:
    298
    Gunnar Hjalmarsson
    Mar 2, 2006
Loading...

Share This Page