How do I insert a NULL value inside an INSERT statement in an SQL Server
database?



Thank you,

Dino


--


-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com

Re: How do I insert a NULL value inside an INSERT statement by Scott

Scott
Fri Dec 19 14:23:10 CST 2003

You could use a variable that has been set to = DBNull.Value in the
statement.


"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:D0JEb.65$ss5.37@clgrps13...
> How do I insert a NULL value inside an INSERT statement in an SQL Server
> database?
>
>
>
> Thank you,
>
> Dino
>
>
> --
>
>
> -------------------------------------------------------------------------
> FIGHT BACK AGAINST SPAM!
> Download Spam Inspector, the Award Winning Anti-Spam Filter
> http://mail.giantcompany.com
>
>
>



Re: How do I insert a NULL value inside an INSERT statement by Miha

Miha
Fri Dec 19 14:41:41 CST 2003

Hi Dino,

Either use parametrized query and pass DBNull.Value as parameter value or
use a sql statement like:
insert into mytable (field1) values (null);

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:D0JEb.65$ss5.37@clgrps13...
> How do I insert a NULL value inside an INSERT statement in an SQL Server
> database?
>
>
>
> Thank you,
>
> Dino
>
>
> --
>
>
> -------------------------------------------------------------------------
> FIGHT BACK AGAINST SPAM!
> Download Spam Inspector, the Award Winning Anti-Spam Filter
> http://mail.giantcompany.com
>
>
>



Re: How do I insert a NULL value inside an INSERT statement by Dino

Dino
Fri Dec 19 15:12:51 CST 2003

I tried it but it does not work. My field is of varchar type, and
DBNull.Value will insert an empthy string. Here is how I did it:

INSERT INTO tblTable (fldField)
VALUES(Iif(cboCombo.enabled, cboCombo.SelectedItem, DBNull.Value))

Any suggestion will be appreciated.

--


-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com


"Scott M." <s-mar@BADSPAMsnet.net> wrote in message
news:%23r7wx3mxDHA.3744@TK2MSFTNGP11.phx.gbl...
> You could use a variable that has been set to = DBNull.Value in the
> statement.
>
>
> "Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
> news:D0JEb.65$ss5.37@clgrps13...
> > How do I insert a NULL value inside an INSERT statement in an SQL Server
> > database?
> >
> >
> >
> > Thank you,
> >
> > Dino
> >
> >
> > --
> >
> >
>
> -------------------------------------------------------------------------
> > FIGHT BACK AGAINST SPAM!
> > Download Spam Inspector, the Award Winning Anti-Spam Filter
> > http://mail.giantcompany.com
> >
> >
> >
>
>



Re: How do I insert a NULL value inside an INSERT statement by Dino

Dino
Fri Dec 19 15:21:57 CST 2003

Hi Miha,

Using 'null' inside INSERT is not supported anymore. I get error to use
System.DBNull.Value instead but that one inserts an empty string instead of
<NULL>.
Thank you,
Dino

--


-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com


"Miha Markic" <miha at rthand com> wrote in message
news:eYQPDCnxDHA.3116@tk2msftngp13.phx.gbl...
> Hi Dino,
>
> Either use parametrized query and pass DBNull.Value as parameter value or
> use a sql statement like:
> insert into mytable (field1) values (null);
>
> --
> Miha Markic - RightHand .NET consulting & development
> miha at rthand com
> www.rhand.com
>
> "Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
> news:D0JEb.65$ss5.37@clgrps13...
> > How do I insert a NULL value inside an INSERT statement in an SQL Server
> > database?
> >
> >
> >
> > Thank you,
> >
> > Dino
> >
> >
> > --
> >
> >
>
> -------------------------------------------------------------------------
> > FIGHT BACK AGAINST SPAM!
> > Download Spam Inspector, the Award Winning Anti-Spam Filter
> > http://mail.giantcompany.com
> >
> >
> >
>
>



Re: How do I insert a NULL value inside an INSERT statement by Bill

Bill
Fri Dec 19 15:33:58 CST 2003

"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:VZJEb.149$ss5.60@clgrps13
> Hi Miha,
>
> Using 'null' inside INSERT is not supported anymore. I get error to
> use System.DBNull.Value instead but that one inserts an empty string
> instead of <NULL>.

can you post the actual code that you have to build and execute the insert?
It sounds like you are mixing levels in what you are doing but it's hard to
tell exactly what's going on from the description.

--
C# newbie... posts are probably inaccurate, inelegant or both!


Re: How do I insert a NULL value inside an INSERT statement by Dino

Dino
Fri Dec 19 16:03:29 CST 2003

Hi,
thank you for your reply. The code looks like:

INSERT INTO tblTable(fldField) VALUES(Iif(cboCombo.Enabled,
cboCombo.SelectedItem, DBNull.Value))

, the fldField is Varchar(10), it allows nulls.

Thank you,
Dino

--


-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com


"Bill Styles" <noemail@nowhere.com> wrote in message
news:%23TJyRfnxDHA.3196@TK2MSFTNGP11.phx.gbl...
> "Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
> news:VZJEb.149$ss5.60@clgrps13
> > Hi Miha,
> >
> > Using 'null' inside INSERT is not supported anymore. I get error to
> > use System.DBNull.Value instead but that one inserts an empty string
> > instead of <NULL>.
>
> can you post the actual code that you have to build and execute the
insert?
> It sounds like you are mixing levels in what you are doing but it's hard
to
> tell exactly what's going on from the description.
>
> --
> C# newbie... posts are probably inaccurate, inelegant or both!
>



Re: How do I insert a NULL value inside an INSERT statement by Bill

Bill
Fri Dec 19 16:15:11 CST 2003

"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:RAKEb.162$ss5.36@clgrps13
> Hi,
> thank you for your reply. The code looks like:
>
> INSERT INTO tblTable(fldField) VALUES(Iif(cboCombo.Enabled,
> cboCombo.SelectedItem, DBNull.Value))

OK... but where is this code? Inside a stored procedure? It isn't a valid
C# or VB.Net statement so what's the context around it?




Re: How do I insert a NULL value inside an INSERT statement by Miha

Miha
Fri Dec 19 16:15:36 CST 2003

Hi Dino,

You are mixing code and sql.

You should do something like:
INSERT INTO tblTable(fldField) VALUES(" + Iif(cboCombo.Enabled,
cboCombo.SelectedItem.ToString(), "null") + ")"

assuming that tblTable and fldField are database names.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com


"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:RAKEb.162$ss5.36@clgrps13...
> Hi,
> thank you for your reply. The code looks like:
>
> INSERT INTO tblTable(fldField) VALUES(Iif(cboCombo.Enabled,
> cboCombo.SelectedItem, DBNull.Value))
>
> , the fldField is Varchar(10), it allows nulls.
>
> Thank you,
> Dino
>
> --
>
>
> -------------------------------------------------------------------------
> FIGHT BACK AGAINST SPAM!
> Download Spam Inspector, the Award Winning Anti-Spam Filter
> http://mail.giantcompany.com
>
>
> "Bill Styles" <noemail@nowhere.com> wrote in message
> news:%23TJyRfnxDHA.3196@TK2MSFTNGP11.phx.gbl...
> > "Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
> > news:VZJEb.149$ss5.60@clgrps13
> > > Hi Miha,
> > >
> > > Using 'null' inside INSERT is not supported anymore. I get error to
> > > use System.DBNull.Value instead but that one inserts an empty string
> > > instead of <NULL>.
> >
> > can you post the actual code that you have to build and execute the
> insert?
> > It sounds like you are mixing levels in what you are doing but it's hard
> to
> > tell exactly what's going on from the description.
> >
> > --
> > C# newbie... posts are probably inaccurate, inelegant or both!
> >
>
>



Re: How do I insert a NULL value inside an INSERT statement by Scott

Scott
Fri Dec 19 16:29:45 CST 2003

Ah, well you've got some VB problems here which could be the culprit. Try
this:

INSERT INTO tblTable (fldField) VALUES(IIF(cboCombo.enabled,
cboCombo.SelectedItem.Value.ToString, DBNull.Value))

You were never bringing back the value of the item in the combobox. Also,
since your DB data type is varchar, then what's wrong with sending an empty
string back?




"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:nRJEb.141$ss5.16@clgrps13...
> I tried it but it does not work. My field is of varchar type, and
> DBNull.Value will insert an empthy string. Here is how I did it:
>
> INSERT INTO tblTable (fldField)
> VALUES(Iif(cboCombo.enabled, cboCombo.SelectedItem, DBNull.Value))
>
> Any suggestion will be appreciated.
>
> --
>
>
> -------------------------------------------------------------------------
> FIGHT BACK AGAINST SPAM!
> Download Spam Inspector, the Award Winning Anti-Spam Filter
> http://mail.giantcompany.com
>
>
> "Scott M." <s-mar@BADSPAMsnet.net> wrote in message
> news:%23r7wx3mxDHA.3744@TK2MSFTNGP11.phx.gbl...
> > You could use a variable that has been set to = DBNull.Value in the
> > statement.
> >
> >
> > "Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
> > news:D0JEb.65$ss5.37@clgrps13...
> > > How do I insert a NULL value inside an INSERT statement in an SQL
Server
> > > database?
> > >
> > >
> > >
> > > Thank you,
> > >
> > > Dino
> > >
> > >
> > > --
> > >
> > >
> >
>
> -------------------------------------------------------------------------
> > > FIGHT BACK AGAINST SPAM!
> > > Download Spam Inspector, the Award Winning Anti-Spam Filter
> > > http://mail.giantcompany.com
> > >
> > >
> > >
> >
> >
>
>



Re: How do I insert a NULL value inside an INSERT statement by Scott

Scott
Fri Dec 19 16:33:40 CST 2003

Oops! and I meant to also mention that the INSERT was built wrong as well!
It should be like this:

Dim ValueToInsert as String

IF cboCombo.enabled then
ValueToInsert = cboCombo.SelectedItem.Value.ToString
ELSE
ValueToInsert = DBNull.Value
END IF

InsertCommand.CommandText = "INSERT INTO tblTable (fldField) VALUES (" &
ValueToInsert & ")"






"Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
news:nRJEb.141$ss5.16@clgrps13...
> I tried it but it does not work. My field is of varchar type, and
> DBNull.Value will insert an empthy string. Here is how I did it:
>
> INSERT INTO tblTable (fldField)
> VALUES(Iif(cboCombo.enabled, cboCombo.SelectedItem, DBNull.Value))
>
> Any suggestion will be appreciated.
>
> --
>
>
> -------------------------------------------------------------------------
> FIGHT BACK AGAINST SPAM!
> Download Spam Inspector, the Award Winning Anti-Spam Filter
> http://mail.giantcompany.com
>
>
> "Scott M." <s-mar@BADSPAMsnet.net> wrote in message
> news:%23r7wx3mxDHA.3744@TK2MSFTNGP11.phx.gbl...
> > You could use a variable that has been set to = DBNull.Value in the
> > statement.
> >
> >
> > "Dino M. Buljubasic" <dino.buljubasic@rivusglobal.com> wrote in message
> > news:D0JEb.65$ss5.37@clgrps13...
> > > How do I insert a NULL value inside an INSERT statement in an SQL
Server
> > > database?
> > >
> > >
> > >
> > > Thank you,
> > >
> > > Dino
> > >
> > >
> > > --
> > >
> > >
> >
>
> -------------------------------------------------------------------------
> > > FIGHT BACK AGAINST SPAM!
> > > Download Spam Inspector, the Award Winning Anti-Spam Filter
> > > http://mail.giantcompany.com
> > >
> > >
> > >
> >
> >
>
>