954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

stored procedure in c#

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....

bharathi_n_r
Light Poster
25 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

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

private void LoadData()
        {
            SqlConnection conn = new SqlConnection("Data Source='SHAWHP\\SQLEXPRESS';Initial Catalog=SoftwareInventory;Integrated Security=SSPI");
            SqlCommand cmd = new SqlCommand("dbo.proc_GetCadyData", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@CadyName", "Cady-A");
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            
            dataSet1.Tables.Clear();
            adapter.Fill(dataSet1, "Table");
            MyGrid.DataSource = dataSet1.Tables["Table"];
            bindingSource1 = new BindingSource(dataSet1, "Table");
            bindingNavigator1.BindingSource = bindingSource1;
            MyGrid.DataSource = bindingSource1;
        }
JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

what is MyGrid referring to in this code ^^^ ???

Elmo_loves_you
Junior Poster in Training
85 posts since Mar 2008
Reputation Points: 30
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You