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

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;
        }

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, networking, learning, and sharing knowledge.