Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 DateTime and Null

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-08-04 : 11:10:08
Can datetime datatype accpet NULL?
I set it as Nullable but i got error if i pass null parameter.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-04 : 11:12:43
yes it can be nullable in sql server.
how are you setting it to null?

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-04 : 11:13:02
quote:
Originally posted by kwikwisi

Can datetime datatype accpet NULL?
I set it as Nullable but i got error if i pass null parameter.


1 Yes
2 Show us the code

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-04 : 11:13:31


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-08-04 : 11:16:13
@date datetime
insert into testtable(sdate,...)
values(@date,...)

If User set as blank at front-end ,i get error like "Input string cannot reconized as valid datetime"

quote:
Originally posted by madhivanan



Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-04 : 11:19:15
What do you mean by blank?
How does the user set the blank value?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-08-04 : 11:21:04
There's a txtbox for user input.I mean if user didn't put anything,get error.

quote:
Originally posted by madhivanan

What do you mean by blank?
How does the user set the blank value?

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-04 : 11:29:10
then you have to do in pseudo code
if (txtDateInput.Test == "")
@myDateParamValue = DbNull.Value;

DbNull.Value is a special null value that you set to SqlParameters

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-08-04 : 11:36:44
u mean like?
if txtdate.text<>"" then
paramdate.value=dbnull.value
else
paramdate.value=txtdate.text
end if

quote:
Originally posted by spirit1

then you have to do in pseudo code
if (txtDateInput.Test == "")
@myDateParamValue = DbNull.Value;

DbNull.Value is a special null value that you set to SqlParameters

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-04 : 11:48:11
if txtdate.text = "" then -- my guess is that you want to put null if the text box is empty
paramdate.value=dbnull.value
else
paramdate.value=txtdate.text
end if

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-08-04 : 11:55:40
Thank u for your guide
quote:
Originally posted by spirit1

if txtdate.text = "" then -- my guess is that you want to put null if the text box is empty
paramdate.value=dbnull.value
else
paramdate.value=txtdate.text
end if

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!

Go to Top of Page
   

- Advertisement -