- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将参数传递给存储过程:
param = CreateInParameter("Result", DbType.Decimal);
param.Value = testresults.Result;
cmd.Parameters.Add(param);
有时 testresults.Result
会是 null
如何将其作为 NULL 传递?
这是我的存储过程:
USE [SalesDWH]
GO
/****** Object: StoredProcedure [dbo].[Insert_TestResults] Script Date: 12/25/2011 23:49:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Insert_TestResults]
-- Add the parameters for the stored procedure here
@TestName varchar (500),
@Result decimal (18,4)=null,
@NonNumericResult varchar (50)=null,
@QuickLabDumpid int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO [SalesDWH].[dbo].[TestResults]
([TestName]
,[Result]
,nonnumericresult
,[QuickLabDumpid])
VALUES
(@TestName,@Result,@nonnumericresult,@QuickLabDumpID)
END
如果 testresults.Result
没有被赋值,它只是作为 0 进入。我如何允许它作为 NULL
进入数据库?
最佳答案
试试这个:
param.Value = testresults.Result==0?DBNull.Value:(object)testresults.Result;
关于c# - 如何为 dbtype decimal 传递空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8633921/
我接管了一些 C# 代码。 代码正在使用一些使用参数的 SQL 访问数据库。 所有字符串参数的类型都是 DbType.AnsiString 而不是 DbType.String。 为什么要使用 DbTy
我有一个结构,我想让它更容易填充 public struct DBParameter { public string parameterName; pu
根据MSDN docs ,列类型/元素的 DbType 属性/属性仅用于数据库创建。 然而,今天,当尝试将数据提交到 SQLCE 数据库上的 IMAGE 列时(不确定是否仅在 CE 上),我收到了“数
当我传递空值时,SQL 更新语句出现问题(或者更好的说法是 DbNull 值)到 DbParameter 对象。当我将 DbNull 值传递给 Value 属性时,DbParameter 对象仍然是
[Microsoft.SqlServer.Server.SqlProcedure] public static void MyMethod() { string con
我将参数传递给存储过程: param = CreateInParameter("Result", DbType.Decimal); param.Value = testresults.Result;
首先,我喜欢指定数据类型并且鄙视 AddWithValue 函数。 我正在 .NET 4.0 下构建一个将在用户 PC 上运行的 SqlCeServer 3.5 本地数据库应用程序。 当我创建表时,我
当我尝试执行此查询时: var q = session.QueryOver(); q.Select(Projections.Avg(x => x.AccountBal
有谁知道等同于 SqlDbType.Bit 的 DbType 是什么? 我正在尝试转换 param[0] = new SqlParameter("@Status", SqlDbType.Bit); p
如何最好地将 System.Data.DbType 枚举值转换为相应的(或至少一个可能的相应)System.Type 值? 例如: DbType.StringFixedLength -> System
我正在尝试为自定义用户类型注册新的 DbType,它只允许我使用 asp.net DbType 来关联我创建的自定义用户类型。例如: /// /// An SQL dialect for P
SqlDataReader SqlTypes 和 DbType 类型访问器有什么区别? 什么时候使用哪个更合适? 最佳答案 如果您的代码需要与提供程序无关并针对多个数据库系统工作,则应避免使用 SQL
我需要从 DbParameter.DbType 打印真实的数据库类型名称,但是当我做这样的事情时 DbParameter.DbType.ToString() 我得到了例如 Int32 而不是 int,
所以,我有以下内容:"SELECT * FROM MyTable;" 当我执行以下操作时,我得到了 TableData,这很有用,但仍然有一些未知的东西? //CommandBehavior.KeyI
我正在使用通用 IDbCommand 函数(在非 SqlCommand 辅助方法中)将 SqlCommand.DbType 设置为 DbType.Date,类似于此: var para
我有一个包含 DateTimeOffset 对象的 SQL Server 2008 数据库。根据 this page , SQL Server Compact provides support for
找到System.Data.DbType 的最佳方法是什么?系统命名空间中基类库类型的枚举值? 最佳答案 一种常见的方法是使用类型映射,明确映射所有支持的类型(不同的连接器/提供程序支持不同的类型)。
我在我们的 SQL Server 2016 数据库中有一个表字段( TotalPrice ) numeric(20, 3)数据类型。 我用过 ulong type 作为我的 C# 属性类型。 publ
我在下面的代码中有一个魔数(Magic Number)... Microsoft.Practices.EnterpriseLibrary.Data.Database db = /* code omit
我正在使用带有 DAAB 4.0 框架的 c# 从 MS SQL 2008 数据库中读取列类型为 dbtype.time 的结果。 我的问题是 MSDN 文档说 dbtype.time 应该映射到一个
我是一名优秀的程序员,十分优秀!