|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
sqlcommand parameters with nullIs 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) 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 > 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 >> > > |
|||||||||||||||||||||||