473,440 Members | 1,792 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,440 software developers and data experts.

Stored Procedure and DataAdapter

Please help me if you know the answer to this. I want to
create a dataAdapter, that fills a dataSet. However, I
have a stored procedure that I want to use, that takes one
int as input. I have been trying this for a few hours now,
and have come no closer.

Nov 13 '05 #1
2 24535
Wayde,

When you use the data adapter to fill a dataset, you can set the
SelectCommand to a SqlCommand where the CommandType property is
CommandType.StoredProcedure.

The CommandText property would be set to the name of the stored
procedure.

Then, call the CreateParameter method on the SqlCommand.

On that instance that is returned from the call to CreateParameter, set
the SqlDbType property to SqlDbtype.Int. Set the parameter value as well.

Then, call the Add method on the SqlParameterCollection returned by the
Parameter property and add the parameter.

Finally, you can call Fill to get your data set.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]


"Wayde" <to*****@hotmail.com> wrote in message
news:09****************************@phx.gbl...
Please help me if you know the answer to this. I want to
create a dataAdapter, that fills a dataSet. However, I
have a stored procedure that I want to use, that takes one
int as input. I have been trying this for a few hours now,
and have come no closer.
Nov 13 '05 #2
Hi, this is the code I am trying. I cannot get it to work,
I think maybe I did not understand some of what you said.
Please help if you can
Expand|Select|Wrap|Line Numbers
  1. SqlDataAdapter testDataAdapter = new SqlDataAdapter();
  2. SqlCommand testCommand =
  3. testDataAdapter.SelectCommand;
  4. testCommand.CommandType=
  5. CommandType.StoredProcedure;
  6.  
  7. testCommand.CommandText="depreciation";
  8. testCommand.Parameters.Add
  9. ("@CategoryID",SqlDbType.Int);
  10. SqlParameter testInput =
  11. testCommand.Parameters.Add("@CategoryID", SqlDbType.Int);
  12. testInput.Direction =
  13. ParameterDirection.Input;
  14. testInput.Value= Convert.ToInt32
  15. (index);
  16.  
  17. DataSet testDataSet = new DataSet();
  18. testDataAdapter.Fill
  19. (testDataSet, "Table1");
  20. //dataGrid1.DataBindings =
  21. testDataSet.Tables["Table1"];
  22. dataGrid1.DataSource = testDataSet;
  23. dataGrid1.DataMember = "invName";
-----Original Message-----
Wayde,

When you use the data adapter to fill a dataset, you can set theSelectCommand to a SqlCommand where the CommandType property isCommandType.StoredProcedure.

The CommandText property would be set to the name of the storedprocedure.

Then, call the CreateParameter method on the SqlCommand.
On that instance that is returned from the call to CreateParameter, setthe SqlDbType property to SqlDbtype.Int. Set the parameter value as well.
Then, call the Add method on the SqlParameterCollection returned by theParameter property and add the parameter.

Finally, you can call Fill to get your data set.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]

"Wayde" <to*****@hotmail.com> wrote in message
news:09****************************@phx.gbl...
Please help me if you know the answer to this. I want to
create a dataAdapter, that fills a dataSet. However, I
have a stored procedure that I want to use, that takes one int as input. I have been trying this for a few hours now, and have come no closer.

.
Nov 13 '05 #3

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

Similar topics

3
by: gh | last post by:
I have made the following stored procedure with the following select statement select * from user select * from order, orderdetail where order.id=orderdetail.id I know I can uses DataReader...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
1
by: AKJTR | last post by:
i'm trying to save on calls back to the db by combining stored procs in one dataadapter. I know they work alone but when i combine the i get an error " Could not find stored procedure...
2
by: Jeff Thur | last post by:
I am trying to Execute a simple Stored Procedure using ASP/VB. I have spent numerous hours with this, researching books and looking on the internet. I can't get a direct answer. THis is my...
10
by: Rich | last post by:
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...
11
by: cj | last post by:
I need to call a stored procedure that passes back 2 strings. I don't think I need a data adapter or a select command or a command builder. So after I create the connection what do I do? Dim...
5
by: limsy | last post by:
Hi ppl, Sorry for asking such a NEWBIE question. I tried looking for answers but cant find. Maybe its too easy. :( I'm used to manual code ADO rather than this .NET wizard and stuff... and i am...
6
by: Bonzol | last post by:
Hey there, I think this is not actually VB, but the language im using is VB. Ive been doing all my code,, NOT using Stored procedures.. so my functions are like.(in 2003) visual basic...
2
by: Robert Bravery | last post by:
HI all, I'm relatively new to this. How can I get the results of a SP (returns a recordset) into a dataset Thanks Robert
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.