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

9 Years
Discussion Span
Last Post by Elmo_loves_you

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


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);
            adapter.Fill(dataSet1, "Table");
            MyGrid.DataSource = dataSet1.Tables["Table"];
            bindingSource1 = new BindingSource(dataSet1, "Table");
            bindingNavigator1.BindingSource = bindingSource1;
            MyGrid.DataSource = bindingSource1;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.