Search This Blog

Saturday, 1 September 2012

Data Base connection in

A SqlConnection is an object, just like any other C# object.  Most of the time, you just declare and instantiate the SqlConnection.  will contain following steps.

  1. Instantiate the SqlConnection.
  2. Open the connection.
  3. Pass the connection to other ADO.NET objects.
  4. Perform database operations with the other ADO.NET objects.
  5. Close the connection.

using (SqlConnection connection = new SqlConnection(connectionString))
           // Create the Command and Parameter objects.
           SqlCommand command = new  SqlCommand("Employee_Insert" 
, connection);
           command.Parameters.AddWithValue("@CityName", txtCity.Text);
           command.Parameters.AddWithValue("@Name", txtName.Text);
           command.CommandType = CommandType.StoredProcedure; 
           catch (SqlException ex){
               throw ex;
           catch (Exception ex){
               throw ex;
Database connection in
Database connection in

No comments:

Post a Comment