How do I pass null values in an Insert statement to an oracle database?

I have this insert statement and I'm getting errors because it is not handling columns where null values are permitted...

strInsert = "INSERT INTO DRAWING" & _
                  "( DRAWING_ID, " & _
                  " DRAWING_NUMBER, " & _
                  " DRAWING_TYPE, " & _
                  " REVISION, " & _
                  " ISSUE_DATE) " & _
                  "VALUES " & _
                  "(" & drDrawing.Item("DRAWING_ID").ToString & "," & _
                          drDrawing.Item("DRAWING_NUMBER").ToString & "," & _
                          drDrawing.Item("DRAWING_TYPE").ToString & "," & _
                          drDrawing.Item("REVISION").ToString & "," & _
                          drDrawing.Item("ISSUE_DATE").ToString & ")"

The statement is passing values from the current data row object to a web service for execution. The problem is there is an error with this statement. I noticed that the only required column is Drawing_ID...if any of the other columns are passing a null then the whole block crashes.

What is the syntax for handling a null column? Any help would be appreciated...or enen a link in the right direction. I am on google right now trying to figure this out.
:-)





LVL 1
imonfireDAMMITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
use bind variables instead of string concatenation.

or, if you want to put in null...



strInsert = "INSERT INTO DRAWING" & _
                  "( DRAWING_ID, " & _
                  " DRAWING_NUMBER, " & _
                  " DRAWING_TYPE, " & _
                  " REVISION, " & _
                  " ISSUE_DATE) " & _
                  "VALUES " & _
                  "(" & drDrawing.Item("DRAWING_ID").ToString & ",NULL,NULL,NULL,NULL)"

Open in new window

sdstuberCommented:
if you use bind variables,  it won't matter if any of the items are NULL or not, nor will you have to convert them to strings either.  You can pass strings as strings, dates as dates, numbers as numbers and nulls as nulls.

String concatenation also opens your application to sql injection.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imonfireDAMMITAuthor Commented:
I decided to use a string builder object and then pass the string builder to a string variable. This way I could pass the string to the webmethod.  THanks for your help I see that string concatenation was not my best bet
imonfireDAMMITAuthor Commented:
I decided to use a string builder to create my string...this made it easier to handle columns where nulls could be accepted because I could place If statements inside my string builder object.
sdstuberCommented:
string builder is still string concatenation and still open to sql injection.

Glad you got it to work, but you'll really benefit in the long run if you switch to using bind variables instead of embedded literals.  Your applications will run faster and your DBA's will start telling everyone else to code like you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.