title: InvalidCastException-failed to convert parameter value from a sqlparameter to a string
body: <p>I am new to application block. </p>
  
  <p>I am trying to insert data in database. Following is the code snap.</p>
  
  <pre><code> private int Id;
      private string Title;
      private string Description;
      private DateTime Start;
      private DateTime End;
      private int User_id;
  
  
      public int id
      {
          get
          {
              return Id;
          }
          set
          {
              Id = value;
          }
      }
      public string title
      {
          get
          {
              return Title;
          }
          set
          {
              Title = value;
          }
      }
      public string description
      {
          get
          {
              return Description;
          }
          set
          {
              Description = value;
          }
      }
      public DateTime start
      {
          get
          {
              return Start;
          }
          set
          {
              Start = value;
          }
      }
      public DateTime end
      {
          get
          {
              return End;
          }
          set
          {
              End = value;
          }
      }
      public int user_id
      {
          get
          {
              return User_id;
          }
          set
          {
              User_id = value;
          }
      }
  </code></pre>
  
  <h2>DAC :</h2>
  
  <pre><code>  public static int addEvent(CalendarEvent cevent)
      {
          try
          {
  
  
              SqlParameter[] sqlParam = new SqlParameter[5];
              sqlParam[0] = new SqlParameter("@title", cevent.title);
              sqlParam[0].Direction = ParameterDirection.Input;
  
              sqlParam[1] = new SqlParameter("@description", cevent.description);
              sqlParam[1].Direction = ParameterDirection.Input;
  
              sqlParam[2] = new SqlParameter("@event_start", Convert.ToString(cevent.start));
              sqlParam[2].Direction = ParameterDirection.Input;
  
              sqlParam[3] = new SqlParameter("@event_end", Convert.ToString(cevent.end));
              sqlParam[3].Direction = ParameterDirection.Input;
  
              sqlParam[4] = new SqlParameter("@user_id", cevent.user_id);
              sqlParam[4].Direction = ParameterDirection.Input;
  
              return Convert.ToInt32(SqlHelper.ExecuteScalar(connectionString, "SaveData", sqlParam));
          }
          catch
          {
              throw;
          }
  </code></pre>
  
  <p>SQLHelper Class:</p>
  
  <pre><code> public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
          {
              //create a command and prepare it for execution
              SqlCommand cmd = new SqlCommand();
              PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);
  
              //execute the command &amp; return the results
              object retval = cmd.ExecuteScalar();
  
              // detach the SqlParameters from the command object, so they can be used again.
              cmd.Parameters.Clear();
              return retval;
  
          }
  </code></pre>
  
  <p>I am getting error  in object <code>retval = cmd.ExecuteScalar()</code>  <strong>Failed to convert parameter value from a SqlParameter to a string</strong>.I  am unable to understand what is the problem.</p>