参数addwithValue中的isdbnull



aim:我想检查值是否为 Null,然后添加空白,否则添加数据

问题:我不确定第一个逗号之后需要放置的内容以将Null更改为 "",然后如果它实际上有数据以导入该数据

    With commandSQL
    .Connection = connection
    .CommandText = "spAddCSVDataLine"  'Stored procedure here
    .CommandType = CommandType.StoredProcedure
    .Parameters.AddWithValue("Name", (IsDBNull(ds.Tables("dataExcel").Rows(j)("Name"))),"",Trim(ds.Tables("dataExcel").Rows(j)("Name"))))

我可以做以下操作,但如果可能

If IsDBNull(ds.Tables("dataExcel").Rows(j)("Name")) Then
.Parameters.AddWithValue("Name", "")
Else
.Parameters.AddWithValue("Name", Trim(ds.Tables("dataExcel").Rows(j)("Name")))
End If

我想您正在寻找If操作员:

With commandSQL
    .Connection = connection
    .CommandText = "spAddCSVDataLine"  'Stored procedure here
    .CommandType = CommandType.StoredProcedure
    .Parameters.AddWithValue("Name", If(IsDBNull(ds.Tables("dataExcel").Rows(j)("Name")), "", Trim(ds.Tables("dataExcel").Rows(j)("Name"))))
End With
Dim row = ds.Tables("dataExcel").Rows(j)
.Parameters.AddWithValue("@Name", If(row.IsNull("Name"), String.Empty, CStr(row("Name"))))

最新更新