title: Pass date parameter to dynamic sql
body: <p>I'm having a very hard time framing this query. The error is - <em>Conversion failed when converting date from character string.</em>
  It is a generic query to work for all tables. All was working good, but i had to add a date parameter.</p>
  
  <p><strong>SQL:</strong></p>
  
  <pre><code>DECLARE @qryUpd nvarchar(MAX), @params nvarchar(MAX), @TableName nvarchar(50),
          @ColName nvarchar(50),@Id nvarchar(50),@ModifiedBy nvarchar(50),
          @ModifiedDate datetime
  
  
  set @qry = 'update '+@TableName+' set Deleted=1, ModifiedBy='+''''+@Id+''',
              ModifiedDate='+''''+@ModifiedDate+''''+' where '+@Colname+'='+''''+
              @Id+''''
  
  execute sp_executesql @qry
  </code></pre>
  
  <p><strong>C#:</strong></p>
  
  <pre><code>public void test(int id, int userid)
  {
    sqlCommand cmd = new sqlcommand("TestFunc",con);
    cmd.commandtype = commandtype.storedprocedure;
    cmd.parameters.addwithvalue("@TableName","tblArea");
    cmd.parameters.addwithvalue("@ColName","AreaId");
    cmd.parameters.addwithvalue("@Id",id);
    cmd.parameters.addwithvalue("@ModifiedBy",userid);
    cmd.parameters.addwithvalue("@ModifiedDate",system.datetime.now.tostring());
  }
  </code></pre>