Monday, March 26, 2012

The correct syntax for returning a DataSet

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.CloseConnect ion)
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/Fo...sp-net/200510/1Hi 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...lasstopic.a sp

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.CloseConnect ion)
> 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/Fo...sp-net/200510/1
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...lasstopic.a sp
>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

0 comments:

Post a Comment