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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top