The problem of inserting null null values into a database table in asp.net

Source: Internet
Author: User
Tags datetime empty null null

Insert operations on a table, such as two fields of datetime and int types, are allowed to be null.

With "sqlcmd." Parameters.Add ("@t12", tb12. Text) Parameter binding. DateTime type, TB12. Text is empty, insert success, do not error, view the value, but for 1900-01-01;int type, with the same statement, TB12. Text is empty, insert successful, do not error, view the value, but 0, with "sqlcmd." Parameters.Add (New SqlParameter ("@t12", Sqldbtype.datetime)); parameters["@t12"]. Value=tb12. Text; " Statement, TB12. Text is an empty insert and an error occurs.

sqlcmd.Parameters.Add(new SqlParameter("@t12",SqlDbType.DateTime));
if (tb12.Text.Length>0)
{
sqlcmd.Parameters["@t12"].Value=tb12.Text
}
else
{
sqlcmd.Parameters["@t12"].Value = System.DBNull.Value;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.