使用asp.net表单在SQL Server 2008中插入空值 [英] inserting null values in sql server 2008 using asp.net forms

查看:83
本文介绍了使用asp.net表单在SQL Server 2008中插入空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条SQL插入语句,该语句将数据发送到SQL Server 2008表.
使用ASP.NET从表单中获取值

有时,这些值将为空白或不需要答案.
如何将这些值作为NULL插入SQL Server?
除非我在黑色字段中填写零,否则asp.net表单将不会保存.但是sql server 2008中的某些字段是允许为null",但是当插入语句被执行时,黑色字段需要为零.

I have a SQL Insert statement that sends data to a SQL Server 2008 table.
The values are picked up from a form using ASP.NET

Sometimes the values will be blank or do not require an answer.
How can I insert these values as NULL into SQL server?
The asp.net form will not save unless I fill in zeros in black fields. But some of the fields in sql server 2008 are "allows null", but when insert statement is excuted it needs zeros for black fields

推荐答案

DbNull.Value是您如何操作选择null以插入.或者,您只使用那些列没有插入语句的SQL,那么它们将保持为空.
DbNull.Value is how you select null to insert. Or you just use SQL that doesn''t have an insert statement for those columns, then they will just stay null.


我认为如果您需要传递字符串数据,请使用vb.net像这样的代码 Dim strValue = string.Empty ,对于c# string strValue = string.Empty
并且您也可以使用DB.Null来实现
您还有一个选择,不要在sql语句中传递参数.
也不要在过程中传递参数值,
在过程参数中分配空值,例如@strValue varchar(10)= null

如果您不传递参数,那么它将起作用.

谢谢
纳恩·查瓦达(Nayan Chavada)
I think if you need to pass string data then use vb.net code like this Dim strValue = string.Empty and for c# string strValue = string.Empty
and you can use DB.Null also for the same
You have one more choice don''t pass parameter in sql statement.
Don''t pass parameter value in procedure as well, also
Assign null in procedure parameter like @strValue varchar(10)=null

if you will not pass parameter then this will work.

Thanks
Nayan Chavada


这篇关于使用asp.net表单在SQL Server 2008中插入空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆