Copying over null values in DB

M

mavrick_101

Hi,

I'm saving data entered by a user. If the user does not enter a value in the
field I would like to insert null value. I want to do this so that I don't
have to write a seperate query for each column and various columns may be
left blank by the user. Instead of entering a blank space I want to enter
null (the columns in the db are nullable).

How can I do that?

Thanks.
 
M

Mark Rae [MVP]

How can I do that?

Firstly, you'll need to provide more information. Specifically:

1) which database are you using?
2) how are you connecting to it?
 
H

Harlan Messinger

mavrick_101 said:
Hi,

I'm saving data entered by a user. If the user does not enter a value in the
field I would like to insert null value. I want to do this so that I don't
have to write a seperate query for each column and various columns may be
left blank by the user. Instead of entering a blank space I want to enter
null (the columns in the db are nullable).

How can I do that?

Thanks.

insert into T (id, name, comment) VALUES (5085, 'John Jones', null)
 
A

Andrew Morton

mavrick_101 said:
I'm saving data entered by a user. If the user does not enter a value
in the field I would like to insert null value. I want to do this so
that I don't have to write a seperate query for each column and
various columns may be left blank by the user. Instead of entering a
blank space I want to enter null (the columns in the db are nullable).

How can I do that?

You can pass DbNull.Value as the value of a parameter to get a null in the
database.
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,089
Latest member
Ketologenic

Latest Threads

Top