title: Cannot update SQL database from C#
body: <p>I am having trouble updating fields in SQL database via stored procedure.
  Following is the c# code. I get no syntax error or anything neither in the stored procedure nor in c# code. </p>
  
  <pre><code>private void btnUpdate_Click(object sender, EventArgs e)
  {
     try
     {
          SqlCommand commandp = new SqlCommand("spUpdateCmpStructure", dbcon.con);
          commandp.CommandType = CommandType.StoredProcedure;
          commandp.Parameters.AddWithValue("@cmpID", txtCmp.Text.ToString());
          commandp.Parameters.AddWithValue("@cmpName", txtCmp.Text.ToString());
          commandp.Parameters.AddWithValue("@cmpDesc", txtDetails.Text.ToString());
          commandp.Parameters.AddWithValue("@cmpAddress", txtAddress.Text.ToString());
          commandp.Parameters.AddWithValue("@cmpType", cbType.Text.ToString());
          commandp.Parameters.AddWithValue("@cmpParent", cbParent.Text.ToString());
  
          dbcon.openConnection();
  
          int check = commandp.ExecuteNonQuery();
  
          if (check &gt; 0)
          {
              MessageBox.Show(txtCmp.Text.ToString() + " Updated");
          }
          else
          {
              MessageBox.Show(txtCmp.Text.ToString() + " Update Failed");
          }
  
          dbcon.closeConnection();
          }
          catch (Exception ex)
          {
               MessageBox.Show(ex.Message);
           }
           finally 
           {
               dbcon.closeConnection();
           }
  </code></pre>
  
  <p>and following is the stored procedure</p>
  
  <pre><code>USE [xxx]
  GO
  
  SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[Spupdatecmpstructure] @cmpID      VARCHAR(10),
                                               @cmpName    VARCHAR(50),
                                               @cmpDesc    VARCHAR(100),
                                               @cmpAddress VARCHAR(50),
                                               @cmpType    VARCHAR(20),
                                               @cmpParent  VARCHAR(50)
  AS
    BEGIN
        UPDATE cmpStructure
        SET    cmpName = @cmpName,
               cmpDesc = @cmpDesc,
               cmpAddress = @cmpAddress,
               cmpType = @cmpType,
               cmpParent = @cmpParent
        WHERE  cmpID = @cmpID
    END 
  </code></pre>