将空单元格传递给sql-server显示" 0"而不是NULL

时间:2018-01-30 13:11:24

标签: sql-server excel-vba vba excel

我通过存储过程将值从excel传递到sql-server。 excel中有两列,其中单元格包含整数或为空。 但是在sql-server中,一列中的空单元格显示为NULL,而另一列中的空单元格显示为" 0"。这是为什么?这两个变量在vba和sql中声明为整数。

如果单元格为空,我需要做什么才能到达NULL?

这是vba代码的一部分:

Dim rst As New ADODB.Recordset
Dim cmd As ADODB.Command
Dim query As String
Global ktghnev As String
Global ktghID As Integer
Dim elsosor As Integer
Dim pt, bank As Integer
Dim fizmod As String
Dim honap As String

With ActiveSheet
elsosor = 3

Do Until .Cells(elsosor, 1) = ""
nevID = .Cells(elsosor, 1)
pt = .Cells(elsosor, 4)
bank = .Cells(elsosor, 5)


 If IsEmpty(Range("D" & elsosor)) = False Or IsEmpty(Range("E" & elsosor)) = False Then


Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "EURfeltoltes"
cmd.Parameters.Append cmd.CreateParameter("@nevID", adInteger, adParamInput, , nevID)
cmd.Parameters.Append cmd.CreateParameter("@ktghID", adInteger, adParamInput, , ktghID)
cmd.Parameters.Append cmd.CreateParameter("@honap", adVarChar, adParamInput, 10, honap)
cmd.Parameters.Append cmd.CreateParameter("@pt", adInteger, adParamInput, , pt)
cmd.Parameters.Append cmd.CreateParameter("@bank", adInteger, adParamInput, , bank)
cmd.Execute

End If

elsosor = elsosor + 1


Loop
End With

这是存储过程:

ALTER PROCEDURE [dbo].[EURfeltoltes] 
@nevID int = null, 
@ktghID int = null,
@honap nvarchar(10) = null,
@pt int = null,
@bank int = null
AS
BEGIN
SET NOCOUNT ON;
insert into bertabla (nevID, ktghelyID, honap, eurpt, eurbank) values (@nevID, @ktghID, @honap, @pt, @bank)
END

0 个答案:

没有答案