473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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/For...p-net/200510/1
Nov 19 '05 #1
2 1637
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/de...classtopic.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.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/For...p-net/200510/1

Nov 19 '05 #2
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/de...classtopic.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
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Adam Warner | last post by:
Hi all, Just before Christmas Chris Torek gave me some great advice about closures in C: <http://groups.google.co.nz/groups?selm=cqcl3k030vj%40news3.newsguy.com&output=gplain> It includes this...
2
by: Jim | last post by:
I'm writing an Invoicing Windows app but I'm writing it to make the code as easy to maintain as possible. Basically, to get any records from my DB, I use two classes: one that sets up the SQL...
3
by: Mike P | last post by:
Is it possible to return a dataset from a stored procedure, or would you need to write the SQL in your .cs file to return the dataset? Any assistance would be really appreciated. Cheers, ...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
3
by: Khurram | last post by:
Hi, Firstly, I will apologise now if I have posted in the wrong discussion group. Please let me know if I have for future reference. Below is the code to a WebMethod that is querying an Access...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
2
by: Andy B | last post by:
I need to make a class and not quite sure how to go about doing this part. I want the class to take user input, build a dataset based on that input and then return it from the class so it can be...
5
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.