title: Which Data Type in C# Should I use to enter data into a Decimal Column in T-SQL?
body: <p>I am having a hard time trying to figure out which data type I would use in C# to enter data into my table in my database which contains a decimal(5,2). When I tried using a C# decimal data type, it said that It had an error converting numeric to decimal. When I tried string, It said that it could not convert nvarchar to decimal. When I tried float... Same thing happened, except the excuse was a "real" data type. double also failed to work. </p>
  
  <p>I have a stored procedure which enters the data into my table, but before I run of and cast data types in my stored procedure to the actual decimal, is there any other way I can rather Convert a c# data type to fit in my decimal(5,2) field?</p>
  
  <pre><code>private void btnAddClientComputer_Click(object sender, EventArgs e)
  {
      SQLCommands comm = new SQLCommands();
      try
      {
          comm.AddClientComputer(int.Parse(cbCustomerID.Text), cbAction.Text, decimal.Parse(tbCost.Text));
      }
      catch (FormatException)
      {
          MessageBox.Show("The cost you have entered is invalid. Please ensure the cost is above 0, and is an actual number", "Invalid Input at Cost", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>public void AddClientComputer(int CustomerID, string Action, decimal Cost)
  {
      try
      {
          comm = new SqlCommand("UspAddClientComputer", conn); // Stored Procedure - see sql file
          comm.Parameters.AddWithValue("@CustomerID", CustomerID);
          comm.Parameters.AddWithValue("@Action", Action);
          comm.Parameters.AddWithValue("@Cost", Cost);
          comm.CommandType = CommandType.StoredProcedure;
          comm.ExecuteNonQuery();
      }
      catch (Exception ex)
      {
          System.Windows.Forms.MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
      }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>CREATE TABLE ClientComputers
              (ClientComputerID int Identity(1,1) primary key clustered
              ,CustomerID int
              ,Action varchar(7) check (Action = 'Upgrade' OR Action = 'Store')
              ,Cost decimal(5,2) check (Cost &gt; 0)
              ,Constraint FKCustomerComputer FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID));
  Go
  </code></pre>
  
  <p>...</p>
  
  <pre><code>CREATE PROCEDURE uspAddClientComputer @CustomerID int, @Action varchar(7), @Cost decimal(5,2)
  AS
  BEGIN TRY
      BEGIN TRANSACTION TrnAddClientComputer;
       INSERT INTO [TCTdb].[dbo].[ClientComputers]
             ([CustomerID]
             ,[Action]
             ,[Cost])
       VALUES
             (@CustomerID
             ,@Action
             ,@Cost)
      COMMIT TRANSACTION TrnAddClientComputer;
  END TRY
  BEGIN CATCH
      ROLLBACK TRANSACTION TrnAddClientComputer;
  
      DECLARE @ErrorMessage NVARCHAR(4000);
      DECLARE @ErrorSeverity INT;
      DECLARE @ErrorState INT;
  
      SELECT 
          @ErrorMessage = ERROR_MESSAGE(),
          @ErrorSeverity = ERROR_SEVERITY(),
          @ErrorState = ERROR_STATE();
  
      RAISERROR (@ErrorMessage,
                 @ErrorSeverity,
                 @ErrorState
                 );
  END CATCH
  GO
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/GhOpX.png" alt="enter image description here"></p>