Link to home
Start Free TrialLog in
Avatar of Abdu_Allah
Abdu_Allah

asked on

DBNull.Value.ToString why it does not work?

Hi, I'm trying to use DBNull.Value.ToString in sql statement to insert nul value but it does not work, any suggestion?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

that won't work indeed...

if you used a Command object with Parameters, then you can assign the DBNull.Value as such to the parameter, then it will work.

please show your code.
Avatar of Abdu_Allah
Abdu_Allah

ASKER


Dim fx as string
If x= 1 then
 fk = DBNull.Value.ToString
else
 fk = 5
end if
 
strSQL = "Insert into mytable(...,fk,...) values("... + fk + ")"

Open in new window

you "could" make your code like this:
Dim fx as string
If x= 1 then
 fk = "NULL"
else
 fk = 5
end if
 
strSQL = "Insert into mytable(...,fk,...) values("... + fk + ")"

Open in new window

however, I repeat, using the db Command + Parameter objects would be better...
Isn't it possible to do that in the way I put?
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial