locked
Having a Problem with Inserting Date/DateTime data RSS RRS feed

  • Question

  • User35436372 posted

    Please visit this link    http://forums.asp.net/post/5456285.aspx

    Wednesday, July 17, 2013 2:17 PM

Answers

  • User1937807931 posted

    I replied to that other post. I sure hope that helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 17, 2013 3:01 PM
  • User1938476581 posted

    Hi,

    I find that you have the solution in here http://forums.asp.net/t/1923070.aspx

    Based on the Exception Details you provided, it is not conclusive that the data coming from the Textbox6 control is the culprit of this error.  There are 10 fields of data being passed to the INSERT statement, but the error simply claims that one of them 'could' be truncated (you are passing more data than one of the fields can accomodate).
    
    But, if it is the Textbox6 field you are really worried about, you might should do a little 'validation' on that data before performing the INSERT statement. I mean, within the INSERT statement you are trying to 'convert' whatever is in that Textbox6 field to a DateTime data type.  In the event someone types anything that is not a valid date ("John Doe", "Junuary 35, 2013", or even "05/42/1985"), this will cause an 'inner error' that is not trapped... and it leaves the INSERT statement (SQL) to handle it.
    
    Possibly, you can use something similar to the following to help catch any flawed date values (or implement a RegEx to that Textbox6 control);
    
    string dateFromText6 = TextBox6.Text;
     DateTime dateParsed = new DateTime();
     DateTime.TryParse(dateFromText6, out dateParsed);
    
    if (dateParsed != new DateTime())
     {
     dateFromText6 = dateParsed.ToString();
     }
     else
     {
     dateFromText6 = DateTime.Now.ToString();
     }
    
    ctn.dmlsmt("insert into ShoppingCart values('" + ss1.bino + "','" + TextBox1.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox2.Text + "','" + TextBox5.Text + "','" + TextBox8.Text + "','" + TextBox7.Text + "','" + dateFromText6 + "'," + ss1.tprc + ")");
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 18, 2013 10:52 PM

All replies

  • User1937807931 posted

    I replied to that other post. I sure hope that helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 17, 2013 3:01 PM
  • User1938476581 posted

    Hi,

    I find that you have the solution in here http://forums.asp.net/t/1923070.aspx

    Based on the Exception Details you provided, it is not conclusive that the data coming from the Textbox6 control is the culprit of this error.  There are 10 fields of data being passed to the INSERT statement, but the error simply claims that one of them 'could' be truncated (you are passing more data than one of the fields can accomodate).
    
    But, if it is the Textbox6 field you are really worried about, you might should do a little 'validation' on that data before performing the INSERT statement. I mean, within the INSERT statement you are trying to 'convert' whatever is in that Textbox6 field to a DateTime data type.  In the event someone types anything that is not a valid date ("John Doe", "Junuary 35, 2013", or even "05/42/1985"), this will cause an 'inner error' that is not trapped... and it leaves the INSERT statement (SQL) to handle it.
    
    Possibly, you can use something similar to the following to help catch any flawed date values (or implement a RegEx to that Textbox6 control);
    
    string dateFromText6 = TextBox6.Text;
     DateTime dateParsed = new DateTime();
     DateTime.TryParse(dateFromText6, out dateParsed);
    
    if (dateParsed != new DateTime())
     {
     dateFromText6 = dateParsed.ToString();
     }
     else
     {
     dateFromText6 = DateTime.Now.ToString();
     }
    
    ctn.dmlsmt("insert into ShoppingCart values('" + ss1.bino + "','" + TextBox1.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox2.Text + "','" + TextBox5.Text + "','" + TextBox8.Text + "','" + TextBox7.Text + "','" + dateFromText6 + "'," + ss1.tprc + ")");
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 18, 2013 10:52 PM