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

Recommended Answers

All 2 Replies

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;

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.