当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net中对数据库表插入null空值的问题

ASP.NET
c# Random快速连续产生相同随机数的解决方案
form身份验证通过后,只能用FormsAuthentication.RedirectFromLoginPage
ASP.NET Global.asax应用程序文件简介
Asp.net下载功能的解决方案代码
asp.net 生成数字和字母组合的随机数
asp.net显示页面执行时间
DiscuzNT 论坛与主站的同步登录与退出
c# 读取Northwind数据库image字段
asp.net 数据访问层基类
C# 文件保存到数据库中或者从数据库中读取文件
ASP.NET 防止用户跳过登陆界面
asp.net 字符串加密解密技术
asp.net 票据简单应用
基于C# 网站地图制作
asp.net GridView 中增加记录的方法
asp.net 自动将汉字转换成拼音第一个字母
运行asp.net时出现 http错误404-文件或目录未找到
System.Runtime.InteropServices.COMException的解决方法
VS2005 180天限制破解方法
asp.net 面试+笔试题目

ASP.NET 中的 asp.net中对数据库表插入null空值的问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 205 ::
收藏到网摘: n/a

    对表进行插入操作,如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;
  }
  
  http://www.cnblogs.com/SAL2928/archive/2006/12/09/587267.html