Last post Jul 18, 2013 10:52 PM by Pengzhen Song - MSFT
Jul 17, 2013 02:17 PM|anirudh_4sag|LINK
Please visit this link http://forums.asp.net/post/5456285.aspx
Jul 17, 2013 03:01 PM|CodeDog|LINK
I replied to that other post. I sure hope that helps.
Jul 18, 2013 10:52 PM|Pengzhen Song - MSFT|LINK
I find that you have the solution in here
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();
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 + ")");