如果没有ASP.NET文本框,如何使用dbnull.value [英] How to use dbnull.value if there is not ASP.NET textbox

查看:93
本文介绍了如果没有ASP.NET文本框,如何使用dbnull.value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net表单中没有任何文本框,但我在服务器端需要dbnull.value。



我尝试过:



I am not having any textbox in the asp.net form but i require dbnull.value in the server side.

What I have tried:

// ModifiedBy
cmd.Parameters.Add("@ModifiedBy", SqlDbType.UniqueIdentifier);
cmd.Parameters["@ModifiedBy"].Value = DBNull.Value;

// ModifiedOn
cmd.Parameters.Add("@ModifiedOn", SqlDbType.DateTime);
cmd.Parameters["@ModifiedOn"].Value = DBNull.Value;





这里ModifiedBy和ModifiedOn字段不能有文本框...现在我该怎么办才能解释我。这些值应保存到具有相同字段的数据库中ModifiedBy和ModifiedOn



Here ModifiedBy and ModifiedOn fields cannot have textboxes... Now what should i do can anyone explain me. These values should be saved into the database having the same fields ModifiedBy and ModifiedOn

推荐答案

如果您的数据库设置为允许两列中的空值,则应该无需任何问题。

如果DB未配置为允许空值,则不能将空值放入该列,并且会出错。在这种情况下,要么更改数据库,要么提供默认值,表明列对您的代码是空的。
Provided your DB is set up to allow nulls in your two columns, that should work without any problems.
If you DB isn't configured to allow nulls, then you can't put a null value to that column, and will get an error. In that case, either change your DB, or provide "default" values that indicate the column is empty to your code.


这篇关于如果没有ASP.NET文本框,如何使用dbnull.value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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