I am rewriting this long INSERT statement and parameters that look like this:
cmd.Parameters.AddWithValue("@Website", General.fnSQLNullValues(tWebsite.Text))
Where is General.fnSQLNullValues:
Public Shared Function fnSQLNullValues(ByVal sValue As Object, Optional ByVal Len As Integer = 999999) As Object If sValue Is Nothing Then Return DBNull.Value fnSQLNullValues = IIf(sValue.ToString.Length = 0, DBNull.Value, Left(sValue.ToString(), Len)) End Function
I don’t like it at all, and there seems to be a lot of code for this,
cmd.Parameters.AddWithValue("@Website" , If(tWebsite.Text , DBNull.Value))
from my understanding that one line of code there DBNull.Value will replace tWebsite.Text as a value if tWebsite.Text is null or not accepted, and it seems to me that I am doing the same thing as another function in General. Is this right and one way is better than the other?
In addition, I get a warning: “It is not possible to deduce a common type, a supposed object” from the second path, but it seems to me that the first method used a universal object anyway, so I don’t know if I should just ignore this warning
source share