All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net中对数据库表插入null空值的问题_.net资料_编程技术

Writer: aaa Article type: Programming skills(编程技巧) Time: 2013/12/13 9:40:16 Browse times: 375 Comment times: 0

asp.net中对数据库表插入null空值的问题_.net资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

asp.net中对数据库表插入null空值的问题_.net资料_编程技术-你的首页-uuhomepage.com

对表进行插入操作,如datetime和int类型的两个字段,都允许为null,
用“sqlcmd.Parameters.Add("@t12",tb12.Text)”参数绑定时。datetime类型时,tb12.Text为空,插入成功,不报错,查看该值,却为1900-01-01;int类型时,用同样语句,tb12.Text为空,插入成功,不报错,查看该值,却为0;用“sqlcmd.Parameters.Add(new SqlParameter("@t12",SqlDbType.DateTime));sqlcmd.Parameters["@t12"].Value=tb12.Text;”语句时,tb12.Text为空插入则报错。

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;
}






There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.