943,917 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 25564
  • C# RSS
Jan 25th, 2008
0

stored procedure in c#

Expand Post »
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....
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bharathi_n_r is offline Offline
25 posts
since Jan 2008
Jan 26th, 2008
0

Re: stored procedure in c#

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


C# Syntax (Toggle Plain Text)
  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. }
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
Aug 15th, 2008
0

Re: stored procedure in c#

what is MyGrid referring to in this code ^^^ ???
Reputation Points: 30
Solved Threads: 0
Junior Poster in Training
Elmo_loves_you is offline Offline
85 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C# Forum Timeline: c# windows application
Next Thread in C# Forum Timeline: Do u have any idea how I can make this software? What do I need to know to start?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC