title: Setting the value of insert parameter of SqlDataSource in codebehind
body: <p>I have this <code>SqlDataSource</code> in my form:</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" 
  
          InsertCommand="INSERT INTO [contact] ([Name], [phone], [email], [comment], [time]) VALUES (@Name, @phone, @email, @comment, @time)" 
          oninserting="SqlDataSource1_Inserting" &gt;
          &lt;InsertParameters&gt;
              &lt;asp:ControlParameter ControlID="TBname" Name="Name" PropertyName="Text" Type="String" /&gt;
              &lt;asp:ControlParameter ControlID="TBphone" Name="phone" PropertyName="Text" Type="String" /&gt;
              &lt;asp:ControlParameter ControlID="TBemail" Name="email" PropertyName="Text" Type="String" /&gt;
              &lt;asp:ControlParameter ControlID="TBmessage" Name="comment" PropertyName="Text" Type="String" /&gt;
          &lt;/InsertParameters&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>And I have this function which has to save the values of TextBoxes in first four fields and current time in fifth field:</p>
  
  <pre><code>protected void SaveToDB(object sender, EventArgs e)
  {
          SqlDataSource1.InsertParameters["time"].DefaultValue = DateTime.Now.ToString();
          SqlDataSource1.Insert();
  }
  </code></pre>
  
  <p>4 of 5 fields get their values from some TextBoxes in my form. now problem is the last field: <code>time</code> which I can't set it's value. When the function runs, gives you this error:</p>
  
  <blockquote>
    <p>Exception Details: System.Data.SqlClient.SqlException: String or
    binary data would be truncated. The statement has been terminated.</p>
  </blockquote>
  
  <p>What should I do?</p>
  
  <p>thank you for taking time.</p>