using System.Data.SqlClient; using System.Data; // Connection string for the database string connectionString = "Data Source=(local);Initial Catalog=MyDatabase;Integrated Security=True"; // Create a new SQLConnection object SqlConnection connection = new SqlConnection(connectionString); // Open the connection connection.Open(); // Create a new SQLCommand object for the stored procedure SqlCommand command = new SqlCommand("GetEmployees", connection); command.CommandType = CommandType.StoredProcedure; // Execute the stored procedure and return the results as a DataSet DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(ds); // Close the connection connection.Close();
using System.Data; using System.Data.SqlClient; // Connection string for the database string connectionString = "Data Source=(local);Initial Catalog=MyDatabase;Integrated Security=True"; // Create a new SQLConnection object SqlConnection connection = new SqlConnection(connectionString); // Open the connection connection.Open(); // Create a new SQLCommand object for the stored procedure SqlCommand command = new SqlCommand("GetCustomerOrders", connection); command.CommandType = CommandType.StoredProcedure; // Set the parameters for the stored procedure command.Parameters.AddWithValue("@CustomerId", 1234); // Execute the stored procedure and return the results as a DataSet DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(ds); // Close the connection connection.Close();In the above example, we are using the StoredProcedure ExecuteDataSet method to execute the "GetCustomerOrders" stored procedure in a database and return the results as a DataSet. We are also passing a parameter to the stored procedure. The package library for the StoredProcedure ExecuteDataSet method is the System.Data.SqlClient namespace.