- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 ASP.net C# web 项目中,我有一个带有参数的查询命令对象。我使用下面的代码来填充参数:
DbCommand command = conn.CreateCommand();
command.CommandText = query;
DbParameter param = command.CreateParameter();
param.ParameterName = parameter;
param.DbType = DbType.String;
param.Value = value;
此代码适用于除空字符串之外的所有字符串。如果我将输入字段留空,它会将值作为“”传递。如果发生这种情况,我会收到以下异常:
ORA-01400: cannot insert NULL into (string)
有没有一种方法可以让我将空白字符串插入数据库?
我使用 Oracle 数据库并使用 System.Data.OracleClient 作为提供者。
最佳答案
如果要插入空字符串,则必须允许 NULL 值。否则 Oracle 会默默地将空字符串转换为 NULL,您将得到异常。
另一种选择是插入一个带有空格的空字符串 ' '
但我认为这会很痛苦。
以下是有关 Oracle 为何采用这种(非标准)方式的更多信息: Why does Oracle 9i treat an empty string as NULL?
关于c# - 带有空字符串的 ASP.Net C# CreateParameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5266005/
如果我调用存储过程 DECLARE @return_value int EXEC @return_value = [dbo].[GetValueProc] @startDate = '1/1/20
请用简单的英语向我解释一下这行是什么意思: Cmd.Parameters.Append _ Cmd.CreateParameter("datapath", adChar, adParamInp
我正在 Windows 7 64 位 SP1(已安装所有更新)上开发 ADO 应用程序(32 位):该应用程序必须在 Win XP 上运行。根据http://support.microsoft.com
在我的 ASP.net C# web 项目中,我有一个带有参数的查询命令对象。我使用下面的代码来填充参数: DbCommand command = conn.CreateCommand(); comm
当我尝试加载我的网站或尝试通过 k ef migration apply 应用我的迁移时出现以下错误 An unhandled exception occurred while processing
我是一名优秀的程序员,十分优秀!