Home All Groups Group Topic Archive Search About

sqlcommand parameters with null

Author
31 Mar 2005 8:36 PM
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

Author
1 Apr 2005 1:49 AM
Val Mazur (MVP)
You could do it next way

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

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



Show quote
"gv" <viat***@musc.edu> wrote in message
news:ecHYEFjNFHA.244@TK2MSFTNGP12.phx.gbl...
>    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
>
Author
1 Apr 2005 3:42 PM
gv
thks

GV




Show quote
"Val Mazur (MVP)" <group***@hotmail.com> wrote in message
news:OvBaW0lNFHA.3492@TK2MSFTNGP09.phx.gbl...
> You could do it next way
>
> NoteCmd.Parameters.Add("@reason", SqlDbType.VarChar, 100).Value = _
>    IIf(txtreason.Text = "", DBNull.Value, txtreason.Text)
>
> --
> Val Mazur
> Microsoft MVP
>
> http://xport.mvps.org
>
>
>
> "gv" <viat***@musc.edu> wrote in message
> news:ecHYEFjNFHA.244@TK2MSFTNGP12.phx.gbl...
>>    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
>>
>
>

AddThis Social Bookmark Button