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 webservertalk.com
http://www.webservertalk.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...op
ic.asp
Alex
http://www.DotNet42.com - The Answer to Your DotNet question
"martinharvey via webservertalk.com" wrote:
> I realise this is a beginners question but i would be grateful for some he
lp
>
> 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 webservertalk.com
> http://www.webservertalk.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...o
pic.asp
>Alex
>http://www.DotNet42.com - The Answer to Your DotNet question
>
>[quoted text clipped - 29 lines]
many thanks for your help with this
Cheers
martin
Message posted via http://www.webservertalk.com
Monday, March 26, 2012
The correct syntax for returning a DataSet
Labels:
asp,
beginners,
class,
datareaders,
dataset,
examplepublic,
grateful,
helpuntill,
net,
realise,
returning,
syntax
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment