Last post Nov 26, 2008 04:23 PM by flyby35
Aug 29, 2006 06:03 PM|Vishal|LINK
Version: ASP.Net 2.0
I'm saving data from a function to an SQL Server 2000 db via a stored procedure. There are a few fields which are conditional and thus need not be passed to the procedure everytime. Under those circumstances I need to store null values in the fields.
The problem is if I the value of the parameter as null, VS throws the error that a required parameter is not passed. I tried setting 'IsNullable' property of the parameter to true but it works for only those fields who are declared NULL in the stored procedure
(For e.g. @DOB DATETIME = NULL).
Strangely, this works well in classic ASP.
Does anyone know how to accomplish this? Note, altering stored procedures is not an option for me.
Thanks a lot!
Aug 29, 2006 07:22 PM|Cos C|LINK
The object you are looking for is called "dbNull". You can assign this as a value to a sqlparameter and it will accomplish what you want.
dim sp as new sqlParameter("@Something", dbNull) 'Assigns the value of dbNull to the parameter.
The behavior of Null has changed from VB 6 (classic ASP) to .NET and the dbNull object was neccessary to bridge this gap.
Aug 29, 2006 07:47 PM|Caddre|LINK
Try the code in the link below it works because it uses the DBNULL in an if/else with static DateTime.Parse so SQL Server is not aware of the null. Hope this helps.
Aug 30, 2006 04:44 AM|Vishal|LINK
Nov 26, 2008 04:23 PM|flyby35|LINK
Caddre, today I have the same problem like this. your link is dead. is there anyway that I can fix this?