| | |
stored procedure in c#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 25
Reputation:
Solved Threads: 0
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....
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....
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
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
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)
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; }
![]() |
Similar Threads
- PHP MySQL 5.0 stored procedure (PHP)
- How to connect a SQL stored procedure to a windows application? (VB.NET)
- Formatted Output in Stored Procedure (MS SQL)
- Pbm with stored procedure (Oracle)
- Can return a Stored Procedure Recordset (MS SQL)
- Help with a stored procedure (MS SQL)
- Help with Stored Procedure (MS SQL)
- how do I run a "disconnected" stored procedure (MS SQL)
- Stored procedure call with ADO (C)
Other Threads in the C# Forum
- Previous Thread: c# windows application
- Next Thread: Do u have any idea how I can make this software? What do I need to know to start?
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# cast check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mailmerge mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox robot save saving serialization server sleep socket sockets sql sql-server statistics stream string stringformatting sun table tcp text textbox thread time timer update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





