473,581 Members | 3,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DBNull to database date-field

Hi

I have defined a table in my database, with 2 date-fields. I have set a
default value to DBNull. I have integrated a nullable datetimepicker control
to my project and set the apropriate NullValue in my datagridview...

Everything works great, with a table-row added manually to the database,
without setting any value to the second date-field. Both the datagridview
and the datetimepicker displays correctly the DBNull value..

My problem however is, how do i add a new row in my program, setting one
date to an actual date, but leaving the other un-set and thereby leaving it
to the DBNull i have setup in the table-design??

When using the addrow method of the dataset i have tried with the field
represented as 'Nothing' but this does not leave the field set to DBNull in
the DB but to a date of 30. december 1899...

Using DBNull.value does not work, but generates an error... How do i add a
new row to my table, leaving one of my date fields un-set (left to
DBNull)???

/Finn

Jul 11 '07 #1
3 6280

"Finn Stampe Mikkelsen" <st****@city.dk wrote in message
news:Os******** ******@TK2MSFTN GP05.phx.gbl...
Hi

I have defined a table in my database, with 2 date-fields. I have set a
default value to DBNull. I have integrated a nullable datetimepicker
control to my project and set the apropriate NullValue in my
datagridview...

Everything works great, with a table-row added manually to the database,
without setting any value to the second date-field. Both the datagridview
and the datetimepicker displays correctly the DBNull value..

My problem however is, how do i add a new row in my program, setting one
date to an actual date, but leaving the other un-set and thereby leaving
it to the DBNull i have setup in the table-design??

When using the addrow method of the dataset i have tried with the field
represented as 'Nothing' but this does not leave the field set to DBNull
in the DB but to a date of 30. december 1899...

Using DBNull.value does not work, but generates an error... How do i add a
new row to my table, leaving one of my date fields un-set (left to
DBNull)???

/Finn
Well, I would suspect that you wouldn't address the field in question and
not put anything in the field, which the database itself would insert the
record with Null data in the record field.

You may have to go to the database itself for the table's field and set the
field to use Null data as the default value when the record is inserted into
the table.

Jul 11 '07 #2

"Mr. Arnold" <MR. Ar****@Arnold.c omskrev i meddelelsen
news:ex******** ******@TK2MSFTN GP03.phx.gbl...
>
"Finn Stampe Mikkelsen" <st****@city.dk wrote in message
news:Os******** ******@TK2MSFTN GP05.phx.gbl...
>Hi

I have defined a table in my database, with 2 date-fields. I have set a
default value to DBNull. I have integrated a nullable datetimepicker
control to my project and set the apropriate NullValue in my
datagridview.. .

Everything works great, with a table-row added manually to the database,
without setting any value to the second date-field. Both the datagridview
and the datetimepicker displays correctly the DBNull value..

My problem however is, how do i add a new row in my program, setting one
date to an actual date, but leaving the other un-set and thereby leaving
it to the DBNull i have setup in the table-design??
Well, I would suspect that you wouldn't address the field in question and
not put anything in the field, which the database itself would insert the
record with Null data in the record field.

You may have to go to the database itself for the table's field and set
the field to use Null data as the default value when the record is
inserted into the table.
Hi

I have been to the table-design and set the default value to be Null. I
can't seem to find any way to pass the null value to the DB.

The field is a Date field. I can't pass DBNull.value, i have tried VB's
Nothing reference but it passes a value leaving the datefield set to dec.
30., 1899... i can't pass "" and i can't ommit the field in the addrow
method...

So i can't seem to find a way that i can do that...

Here's my code

Kunder.Arbejdso pgaver.AddArbej dsopgaverRow(Ar bejdsNummerText Box.Text,
StolTypeTextBox .Text, _ Kunder._Kunder. Rows(KunderBind ingSource.Posit ion) ,
DatoStartDateTi mePicker.Value, DatoSlutDateTim ePicker.Value)

It's the last field (DatoSlutDateTi mePicker.Value) i need to pass to the DB
as a null value, since it depick's a date marking the end of a project. This
date is not set, when creating a project and logically should be set to
null..

I have worked around the DBNull problem with DateTimePicker and created a
control handling this and my column in my DataGridView is setup to show the
NullValue with the correct text..

Now i can't seem to create the project by adding a new row, passing this
DBNull value in the field...

/Finn

Jul 11 '07 #3

"Finn Stampe Mikkelsen" <st****@city.dk wrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
>
<snipped>
Hi

I have been to the table-design and set the default value to be Null. I
can't seem to find any way to pass the null value to the DB.
>
The field is a Date field. I can't pass DBNull.value, i have tried VB's
Nothing reference but it passes a value leaving the datefield set to dec.
30., 1899... i can't pass "" and i can't ommit the field in the addrow
method...
You don't pass anything in the field from your program. You don't address
the field period on the table record. You just leave the field alone. And
when the record is inserted into the table, the database will put the NULL
value in the table's field for that record by itself.

So you're saying that you can't determine if that datepicker value is less
than 01/01/1900 and say that's an indication that it's NULL, just omit the
field, don't put that data into the table record's date filed, and insert
the record?
>
So i can't seem to find a way that i can do that...

Here's my code
<snipped>
It's the last field (DatoSlutDateTi mePicker.Value) i need to pass to the
DB as a null value, since it depick's a date marking the end of a project.
This date is not set, when creating a project and logically should be set
to null..

I have worked around the DBNull problem with DateTimePicker and created a
control handling this and my column in my DataGridView is setup to show
the NullValue with the correct text..
Most would just correct the value by putting vbNullstring as the text value
to be shown (blank), if the date is less than 01/01/1900 as that's an
indication that the date value was NULL.

It's an old problem that was even there in VB 6 concerning the display of
data from a date field on a record and it's a NULL value, which is being
shown as 12/31/1899.

work around it

Jul 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4898
by: Patrick.O.Ige | last post by:
When i try and use this (Where Unit is a column in my Table):- If Unit Is DBNull.Value Then Return "1" Else Return "2" End If I always have 2 returned! Even when Unit is NULL! I want a case if a column is NULL the it xhould return '1 and if not '2' How does DBNull.Value work?
2
11152
by: Oleg Ogurok | last post by:
Hi all, I have a DatePicker ASP.NET control that allows users to enter date (e.g. a calendar control). The control has the following property public DateTime Value { get; set; } I've placed the control into a datagrid now I'm trying to bind values from database to the datagrid.
10
2408
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
1
1535
by: bafidi | last post by:
i cant use DBNull.Value i have a date property Private m_son_degisiklik_tarihi As Date Public Property Son_Degisiklik_Tarihi() As Date Get Return m_son_degisiklik_tarihi End Get Set(ByVal Value As Date)
3
1796
by: Brenny | last post by:
Hi, I'm using access database and a table has a boolean column. I want to hold 1,0 and DBNull values in this column. But I cannot DBNull value, how can I hold DBNull value in the access database in boolean column?
6
5941
by: Charlie Brown | last post by:
When checking for NULL values from a database, normally I would use If Not row("NetSales") Is DBNull.Value Then NetSales = row("NetSales") End If However, if I use a typed dataset then I can't check for NULL the same way
3
1495
by: Liverpool fan | last post by:
Hi all and thanks to those who respond to this. I have a data maintenance form which I am using to update data in my database. In the update routine I use the following code; ssql = "UPDATE Email_Usage SET = @Date," & _ "pagesgenerated = @PagesGenerated," & _ "pagesemailed = @PagesEmailed," & _ "customersemailed =
19
19316
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
3
10083
by: shlabadoo | last post by:
Hello, I searched for quite a while for an answer to this, but with no joy. All the answeres seem to be how to deal with getting a DBNull value out of a database, not to put it in . Perhaps I am not using the right search terms, but here we go. Background: I have a database with 2 tables with the following pertinent fields: EMPLOYEE ...
3
5434
by: John | last post by:
Hi What is the difference between Nothing and dbnull.value? Thanks Regards
0
7861
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8167
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6548
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5358
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3802
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.