The correct syntax for returning a DataSet

  • Thread starter martinharvey via DotNetMonster.com
  • Start date
M

martinharvey via DotNetMonster.com

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
 
G

Guest

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
 
M

martinharvey via DotNetMonster.com

Alex said:
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]


many thanks for your help with this

Cheers

martin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top