T
Thomas Ficker
I use stored procedures in most of my programs and in many instances one or
more of the parameters being passed can be null. I am looking for the most
efficent way to test for a null value then pass it to the parameter object.
Here is an example of what I do now, paying special attention to the
Parameter functions:
Sub AddRecord (byval FirstName as string, byval LastName as string)
Dim cnn as new SQLClient.SQLConnection(strcnn)
Dim cmd as new SQLClient.SQLCommand
cnn.open : cmd.Connection = cnn : cmd.CommandType =
adStoredProcedure
cmd.CommandText = "spAddRecord"
If Trim(FirstName) <> "" Then
cmd.Parameters.Add("@FirstName",sqldbtype.varchar).Value =
FirstName
Else
cmd.Parameters.Add("@FirstName",sqldbtype.varchar).Value =
System.DBNull.Value
End If
If Trim(LastName) <> "" Then
cmd.Parameters.Add("@LastName",sqldbtype.varchar).Value =
LastName
Else
cmd.Parameters.Add("@LastName",sqldbtype.varchar).Value =
System.DBNull.Value
End IF
cmd.ExecuteNonQuery
cnn.close : cnn = Nothing : cmd=Nothing
End Sub
My questions are:
1. How can I test for Null values in other data type.
2. Is there a better way to do this?
I haven't found any real soild documentation on this on the web or in my
VB.Net and VS.Net books.
Thanks,
Tom
more of the parameters being passed can be null. I am looking for the most
efficent way to test for a null value then pass it to the parameter object.
Here is an example of what I do now, paying special attention to the
Parameter functions:
Sub AddRecord (byval FirstName as string, byval LastName as string)
Dim cnn as new SQLClient.SQLConnection(strcnn)
Dim cmd as new SQLClient.SQLCommand
cnn.open : cmd.Connection = cnn : cmd.CommandType =
adStoredProcedure
cmd.CommandText = "spAddRecord"
If Trim(FirstName) <> "" Then
cmd.Parameters.Add("@FirstName",sqldbtype.varchar).Value =
FirstName
Else
cmd.Parameters.Add("@FirstName",sqldbtype.varchar).Value =
System.DBNull.Value
End If
If Trim(LastName) <> "" Then
cmd.Parameters.Add("@LastName",sqldbtype.varchar).Value =
LastName
Else
cmd.Parameters.Add("@LastName",sqldbtype.varchar).Value =
System.DBNull.Value
End IF
cmd.ExecuteNonQuery
cnn.close : cnn = Nothing : cmd=Nothing
End Sub
My questions are:
1. How can I test for Null values in other data type.
2. Is there a better way to do this?
I haven't found any real soild documentation on this on the web or in my
VB.Net and VS.Net books.
Thanks,
Tom