How to fill DataSet from stored procedure?
It goes a bit like this . . . Dim cmd As New OleDb.OleDbCommand cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "MyStoredProcedure" cmd.Connection = MyConnection -- OHM ( Terry Burns ) . . . One-Handed-Man . . . If U Need My Email ,Ask Me Time flies when you don't know what you're doing
I know this, but how actually to read the data returned by the stored procedure and put it in the dataset?
I assume you are using MS SQL Server. -- Code Start -- Dim sqlCon As New SqlConnection (<connection string>) Dim sqlAdp As New SqlDataAdapter Dim sqlCmd As New SqlCommand Dim ds As New DataSet sqlCmd.Connection = sqlCon sqlCmd.CommandText = <sp name> sqlCmd.CommandType = CommandType.StoredProcedure ' Add any parameters to the stored proc here using sqlCmd.Parameters collection sqlAdp.SelectCommand = sqlCmd sqlAdp.Fill (ds) -- Code End -- How to fill DataSet from stored procedure?
Create a xxxCommand object around the stored procedure and then use that object when creating the xxxDataAdapter. Air code: Dim cnn As SqlConnection = New SqlConnection("Data Source=MySrv;Initial Catalog=MyDB;Integrated Security=SSPI") cnn.Open() Dim cmd As SqlCommand = New SqlCommand("MySP", cnn) cmd.CommandType = CommandType.StoredProcedure Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim ds As DataSet da.Fill(ds, "MyTable")
Try this..... ' Open db connection Dim cnn As New SqlConnection(CONNECTION_STRING) cnn.Open() ' Set command for the stored procedure Dim cmd As New SqlCommand With cmd .CommandType = CommandType.StoredProcedure .Connection = cnn .CommandText = "CustOrderHist" .Parameters.Add("@CustomerID", "ALFKI") End With ' Create data adapter Dim da As New SqlDataAdapter(cmd) ' Fill dataset from adapter Dim ds As New DataSet da.Fill(ds) Hope this helps.
Maybe my question was wrong. I needed to know does any data will be returned from stored procedure select statment to dataset. I mean when the sqlcommand.commandType is text and .CommandText is the SQL statemen everything works ok, but when the same sql statment is in stored procedure does the DataSet iss filled properly?
Whatever the stored procedure returns will be populated in the dataset - exactly the same as if the commandType is Text and a SQL statement is provided. Make sure the stored procedure you are using is returning what you are expecting in query analyser or similar then use the code posted previously - it should work. Hope this helps. select
select Yes, IF the stored procedure returns a resultset. If it's a stored procedure that only sends back a return value and/or fills output parameters then it won't fill the DataSet, but then you wouldn't choose such a stored procedure in the first place, would you?
1.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
2.Fill strongly type dataset from stored procedure
Dear all, I have a file-strongly type dataset, that have two independent table inside it. I want to fill the two table in the dataset by one stored procedure(have two select sql on it) how can i do e.g. create spname .. SELECT * FROM table1 SELECT * FROM table2 GO and Dataadapter.fill(dataset.table1) but how about table2
3.Filling a muti-table typed dataset using a stored procedure
Hi, I have a stored procedure that makes two separate SELECT. I then create a typed dataset and drag the stored procedure to the designer which creates 2 tables.... the first one by default has the name of the stored procedure and the second one has the name Table1. I rename both tables to more significant names. I am trying to fill the typed dataset with a call to the stored procedure.... however, calling Fill will actually create 2 additional tables on my dataset. I have filled untyped datasets with multiple table stored procedures but I can't seem to be able to solve it for typed datasets. Thanks, Jeronimo
5.how to fill a dataset from a DB2 stored procedure
Hi all gurus, I am using a DB2 stored procedure which selects some data from a table and opens a cursor. I want to take this data in a Dataset... but when I use the Dataadapter's fill method the dataset doesnot contain any data. How can I fetch the data from the cursor to the Dataset? thanks and regards, Ashish Sheth
6. filling dataset with Sybase stored procedure
Users browsing this forum: No registered users and 44 guest