title: System.Data.SqlClient.SqlException: 'Operand type clash: datetime2 is incompatible with decimal
body: <p>I have a Stored Procedure which requires a structured parameter. I'm trying to call the stored procedure from my C# code and I get following error.</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException: 'Operand type clash: datetime2 is
    incompatible with decimal The data for table-valued parameter
    "@TableType" doesn't conform to the table type of the parameter. SQL
    Server error is: 200, state: 7'</p>
  </blockquote>
  
  <p>Below is my stored procedure which is available in the database.</p>
  
  <pre><code>CREATE PROCEDURE dbo.spProcessData
      @TableType AS dbo.TblTypeHourlyData READONLY
  AS
  BEGIN
      SET NOCOUNT ON;
  
  
  END
  </code></pre>
  
  <p>This is my table type script.</p>
  
  <pre><code>CREATE TYPE dbo.TblTypeHourlyData AS TABLE 
  (
      Name NVARCHAR(50),
      RecordDate DATETIME,
      Amount  DECIMAL(18,2)
  )
  GO
  </code></pre>
  
  <p>I call the SP by passing the required parameter (data table). However, it returns an error in the <code>var executeNonQuery = command.ExecuteNonQuery();</code> line.</p>
  
  <pre><code>        List&lt;HourlyData&gt; data = .................
          using (var connection = CreateConnection())
          {
              using (var command = connection.CreateCommand())
              {
                  command.CommandText = "dbo.spProcessData";
                  command.CommandType = CommandType.StoredProcedure;
  
                  DataTable paramDT = new DataTable();
                  using (var reader = ObjectReader.Create(data))
                  {
                      paramDT.Load(reader);
                  }
  
                  var param1 = new SqlParameter("@TableType", SqlDbType.Structured)
                  {
                      TypeName = "dbo.TblTypeHourlyData",
                      Value = paramDT
                  };
  
                  command.Parameters.Add(param1);
                  connection.Open();
                  var executeNonQuery = command.ExecuteNonQuery(); // ERROR
                  connection.Close();
  
                  var value = executeNonQuery &gt; 0;
                  return value;
              }
          }
  </code></pre>
  
  <p>For the "data" variable, I already have a data set. <code>HourlyData</code> class has the same structure as the table type.</p>
  
  <pre><code>public class HourlyData
  {
          [DataMember]
          public string Name { get; set; }
  
          [DataMember]
          public DateTime? RecordDate{ get; set; }
  
          [DataMember]
          public decimal? Amount{ get; set; }
  }
  </code></pre>