stored procedure in c#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 25
Reputation: bharathi_n_r is an unknown quantity at this point 
Solved Threads: 0
bharathi_n_r bharathi_n_r is offline Offline
Light Poster

stored procedure in c#

 
0
  #1
Jan 25th, 2008
Hi fellows,
I have learned to create stored procedures,but dont know on how to implement it in my code...I have a dataadapter called ada and a dataset ds..The form consists of three textboxes and a combobox...I need the valuse from the database to the comboox...How to fill the dataset and how to use the dataadapter....explain with a sample code....


Thanks in advance....
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: stored procedure in c#

 
0
  #2
Jan 26th, 2008
Using a Stored Procedure with a Data Adapter
In this example, I have a database named SoftwareInventory with a table named Software and a Stored procedure named proc_GetCadyData that takes one parameter named @CadyName (nvarchar(50))

Establish an SQL Connection
Then create an SQLCommand. Set it to use the CommandType of StoredProcedure.
Add the @CadyName parameter
Create the DataAdapter, and use this new SQLCommand as its parameter.
Fill the dataset from the adapter.

That's all there is to it...

Jerry


  1. private void LoadData()
  2. {
  3. SqlConnection conn = new SqlConnection("Data Source='SHAWHP\\SQLEXPRESS';Initial Catalog=SoftwareInventory;Integrated Security=SSPI");
  4. SqlCommand cmd = new SqlCommand("dbo.proc_GetCadyData", conn);
  5. cmd.CommandType = CommandType.StoredProcedure;
  6. cmd.Parameters.AddWithValue("@CadyName", "Cady-A");
  7. SqlDataAdapter adapter = new SqlDataAdapter(cmd);
  8.  
  9. dataSet1.Tables.Clear();
  10. adapter.Fill(dataSet1, "Table");
  11. MyGrid.DataSource = dataSet1.Tables["Table"];
  12. bindingSource1 = new BindingSource(dataSet1, "Table");
  13. bindingNavigator1.BindingSource = bindingSource1;
  14. MyGrid.DataSource = bindingSource1;
  15. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Re: stored procedure in c#

 
0
  #3
Aug 15th, 2008
what is MyGrid referring to in this code ^^^ ???
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC