Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I realise this is a simple question but I wonder if anyone can help me with this:

 

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

Posted

Dim ds as New DataSet

Dim da as New DataAdapter

 

da.SelectCommand = cmd

 

da.Fill(ds)

 

Notice that the data adapter opens and closes the connection. Remember to clean up your objects too.

Posted

Correct Syntax for returning a dataset

 

Dim ds as New DataSet

Dim da as New DataAdapter

 

da.SelectCommand = cmd

 

da.Fill(ds)

 

Notice that the data adapter opens and closes the connection. Remember to clean up your objects too.

 

many thanks for your help with this

 

martin

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...