sqlcommand parameters with null

  • Thread starter Thread starter gv
  • Start date Start date
G

gv

Is there an easier \ shorter way of doing this?

If txtreason.Text = "" Then
NoteCmd.Parameters.Add("@reason", SqlDbType.VarChar, 100).Value
= vbNull
Else
NoteCmd.Parameters.Add("@reason", SqlDbType.VarChar, 100).Value
= txtreason.Text
End If

thanks
gv
 
You could do it next way

NoteCmd.Parameters.Add("@reason", SqlDbType.VarChar, 100).Value = _
IIf(txtreason.Text = "", DBNull.Value, txtreason.Text)
 
Back
Top