473,385 Members | 2,162 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,385 software developers and data experts.

fill dataset from Sql Server stored procedure?

I have a stored procedure on Sql Server2k. I can fill a data table which I
can append to a dataset using an ADODB recordset object which gets populated
from a command object that runs the sp. I was hoping to use a DataAdapter.
But I think the data adapter only uses select statements. I could write the
sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever. I
will guess that I will need to stick with the ADODB recordset object for
this. But I am open to any better suggestions on how to fill the
datatable/dataset with the data from the stored procedure.

Thanks,
Rich
Nov 21 '05 #1
10 13260
OK. Now I remember my dilema. ADO.Net doesn't use recordset objects. So
how can I fill my data table/dataset from a stored procedure?

"Rich" wrote:
I have a stored procedure on Sql Server2k. I can fill a data table which I
can append to a dataset using an ADODB recordset object which gets populated
from a command object that runs the sp. I was hoping to use a DataAdapter.
But I think the data adapter only uses select statements. I could write the
sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever. I
will guess that I will need to stick with the ADODB recordset object for
this. But I am open to any better suggestions on how to fill the
datatable/dataset with the data from the stored procedure.

Thanks,
Rich

Nov 21 '05 #2
Of course, the SqlDataReader. It's all coming back to me. Just haven't done
this for a while. Actually, I want to populate a datagrid with this. So I
am thinkin I will populate the datatable from the Reader object and set the
datagrid datasource to the datatable. Am I on track here? can a reader be
used as a datasource?

"Rich" wrote:
OK. Now I remember my dilema. ADO.Net doesn't use recordset objects. So
how can I fill my data table/dataset from a stored procedure?

"Rich" wrote:
I have a stored procedure on Sql Server2k. I can fill a data table which I
can append to a dataset using an ADODB recordset object which gets populated
from a command object that runs the sp. I was hoping to use a DataAdapter.
But I think the data adapter only uses select statements. I could write the
sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever. I
will guess that I will need to stick with the ADODB recordset object for
this. But I am open to any better suggestions on how to fill the
datatable/dataset with the data from the stored procedure.

Thanks,
Rich

Nov 21 '05 #3
> how can I fill my data table/dataset from a stored procedure?

Hi,
I am not an expert, but set the CommandType
to StoredProcedure.
CommandText to your StoredProc name.
I was hoping to use a DataAdapter.
But I think the data adapter only uses select statements

DataAdapter has Select, Insert and Delete statements.

Then, DataAdapter.Fill(DataTable)
Of course, Connection must be open.
Hope that helps,
Roger

Nov 21 '05 #4
The following code will connect to an SQL Server 2000 database, retrieve
records from a table, fill a dataset, and bind the dataset to a datagrid
object.

dim conn as SqlConnection = new SqlConnection("Data
Source=(local);Integrated Security=SSPI; Initial Catalog=northwind")

dim da as SqlDataAdapter = new SqlDataAdapter("SELECT CustomerID,
ContactName FROM Customers", thisConnection)

dim ds as dataset = new DataSet

da.Fill(ds, "Customers")
datagrid1.datasource = ds
datagrid1.databind

It isn't necessary to call the databind method if you're creating a Windows
Forms application, but is required for ASP.NET.

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
I have a stored procedure on Sql Server2k. I can fill a data table which I
can append to a dataset using an ADODB recordset object which gets
populated
from a command object that runs the sp. I was hoping to use a
DataAdapter.
But I think the data adapter only uses select statements. I could write
the
sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever.
I
will guess that I will need to stick with the ADODB recordset object for
this. But I am open to any better suggestions on how to fill the
datatable/dataset with the data from the stored procedure.

Thanks,
Rich

Nov 21 '05 #5
Oops.. when converting this code from C# to VB.NET, I missed changing
"thisconnection" to "conn". Change that and the code should work.

"Steve" <sp*********@yahoo.com> wrote in message
news:O7**************@TK2MSFTNGP15.phx.gbl...
The following code will connect to an SQL Server 2000 database, retrieve
records from a table, fill a dataset, and bind the dataset to a datagrid
object.

dim conn as SqlConnection = new SqlConnection("Data
Source=(local);Integrated Security=SSPI; Initial Catalog=northwind")

dim da as SqlDataAdapter = new SqlDataAdapter("SELECT CustomerID,
ContactName FROM Customers", thisConnection)

dim ds as dataset = new DataSet

da.Fill(ds, "Customers")
datagrid1.datasource = ds
datagrid1.databind

It isn't necessary to call the databind method if you're creating a
Windows Forms application, but is required for ASP.NET.

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
I have a stored procedure on Sql Server2k. I can fill a data table which
I
can append to a dataset using an ADODB recordset object which gets
populated
from a command object that runs the sp. I was hoping to use a
DataAdapter.
But I think the data adapter only uses select statements. I could write
the
sp in my vb.net app, but the sp references UDF's I wrote in the Sql
Sever. I
will guess that I will need to stick with the ADODB recordset object for
this. But I am open to any better suggestions on how to fill the
datatable/dataset with the data from the stored procedure.

Thanks,
Rich


Nov 21 '05 #6
Rich,

When you combine the answers from Roger and Steve, than you have your
answer,

I hope this helps,

Cor
Nov 21 '05 #7
Actually, I ended up using a datareader to load the data from the stored
procedure and then loaded a datatable in a dataset from the datareader and
binded that to the datagrid. My question is if it is possible to use a
dataAdapter with a stored procedure? I don't think it is, is it?

"Cor Ligthert" wrote:
Rich,

When you combine the answers from Roger and Steve, than you have your
answer,

I hope this helps,

Cor

Nov 21 '05 #8
Rich,

Here is an example. Note that this particular stored procedure requires a
parameter. Also note that this code uses OleDb objects, but you can easily
change it to use SQLClient:

Public Function GetRentedTapesByCustomerID(ByVal CustomerID As Integer)
As DataTable

Dim cn As OleDb.OleDbConnection = Settings.GetConnection()
Dim cmd As New OleDb.OleDbCommand
Dim da As New OleDb.OleDbDataAdapter
Dim dt As New DataTable
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "RentedTapesByCustomerID"
cmd.Parameters.Add("@CustomerID", CustomerID)
cn.Open()
cmd.Connection = cn
da.SelectCommand = cmd
da.Fill(dt)
cn.Close()

Return dt

End Function

Kerry Moorman
"Rich" wrote:
Actually, I ended up using a datareader to load the data from the stored
procedure and then loaded a datatable in a dataset from the datareader and
binded that to the datagrid. My question is if it is possible to use a
dataAdapter with a stored procedure? I don't think it is, is it?

"Cor Ligthert" wrote:
Rich,

When you combine the answers from Roger and Steve, than you have your
answer,

I hope this helps,

Cor

Nov 21 '05 #9
why recode for what is already coded? use a data adapter it will do all the
reader work and such for you... using a reader to do it alone is dangerous
because you can only have one open at once and have to make sure you close
it when done, etc...
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Actually, I ended up using a datareader to load the data from the stored
procedure and then loaded a datatable in a dataset from the datareader and
binded that to the datagrid. My question is if it is possible to use a
dataAdapter with a stored procedure? I don't think it is, is it?

"Cor Ligthert" wrote:
Rich,

When you combine the answers from Roger and Steve, than you have your
answer,

I hope this helps,

Cor

Nov 21 '05 #10
Thanks all for your replies. I didn't think the datareader was the way to
go. Also, I broke down and used the SqlDataAdapter wizard. It had stored
procedures as an optioin (I am such a lamo). Anyway, now the explanations
all make sense. Everything working OK, finally.

Thanks all for your help.

"Rich" wrote:
Actually, I ended up using a datareader to load the data from the stored
procedure and then loaded a datatable in a dataset from the datareader and
binded that to the datagrid. My question is if it is possible to use a
dataAdapter with a stored procedure? I don't think it is, is it?

"Cor Ligthert" wrote:
Rich,

When you combine the answers from Roger and Steve, than you have your
answer,

I hope this helps,

Cor

Nov 21 '05 #11

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

Similar topics

4
by: Mervin Williams | last post by:
I have several tables involved in my application, but the two in question here are the company and address tables. The company table has business_address_id and mailing_address_id columns, which...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
9
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
1
by: Nikolay Petrov | last post by:
How to fill dataset with multiple tables and set their relaition? Can I get the relations from the SQL server? Also I would like to do it using stored procedures. TIA
5
by: moondaddy | last post by:
I have a website where cataloge pages are populated by calling a stored procedure on sql server. I use the sql data adapter's fill method to call this stored procedure and fill the dataset. about...
1
by: SomebodyElse | last post by:
Hi. Apologies if this has been asked here before - I've searched & searched but can't find anything. It's probably my serach parameters, but I'm having trouble even describing it to a search...
2
by: john wright | last post by:
I have a stored procedure that returns a dataset. I want this dataset to fill a tree view. Here is the Stored Procedure Query SELECT Product.Product_#, Product.Part_Number, Status.Status,...
6
by: Laura K | last post by:
This is probably a simple question but I want to make sure I am doing it right. I have a spoc with two select statements which results in two tables. Very Basic ...
5
by: John | last post by:
Hi, I am developing a windows app using C# 2005. This app uses SQL Server or Oracle database depending on the what the user is using. Can I create one typed dataset and use it for SQL Server and...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.