473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Nothing Does Not Work As Documented

VS 2003

The documentation says " Nothing keyword represents the default value of any
data type" this is simply not true and causing a lot of problems.

1) Consider an SQL table of 3 columns:

Column1 bit no nulls
Column2 string no nulls
Column3 DateTime no nulls

2) then, set each column in a DataSet, DataRowto nothing
Column1 = nothing ' should be 0 false
Column2 = nothing ' should be string.empty
Column3 = nothing ' should be 01/01/0001
If you look at the values in DataRow, Column 1,2 & 3 they do not reflect the
defaults, although they all have some value in them (particularly true with
DateTime)

3) Now, using a DataAdapter for the table add the DataRow to the DataSource.

It fails everytime with a message like: "Cannot write null to non-nullable
Column1".

4) If you manually set the DataRow columns (1,2,3) to their default values,
it works every time.

What does that mean? Nothing does not work. Very frustrating.

Please advise.

Bob Day

Nov 20 '05 #1
6 1692
Bob, setting the column to nothing does just that, it sets it to the default
value of the object not to the default value that you assigned the object.

Column1 = nothing

Then try referencing Column1 will give you a null reference exception. All
of those columns are now null, so if you try adding a row with them in it,
you'll get that exception.

The confusion comes from the word Default. Any given column can havea
default value that you assign. The Default value for a Column is nothing,
meaning that you haven't defined it yet.

Try setting Column2 to string.Empty for instance, Column1 to 0 and column3
to 01/01/0001 and it will work. Also, since you set them to nothing, they
very well may be garbage collected and cease to exist.

HTH,

Bill
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
VS 2003

The documentation says " Nothing keyword represents the default value of any data type" this is simply not true and causing a lot of problems.

1) Consider an SQL table of 3 columns:

Column1 bit no nulls
Column2 string no nulls
Column3 DateTime no nulls

2) then, set each column in a DataSet, DataRowto nothing
Column1 = nothing ' should be 0 false
Column2 = nothing ' should be string.empty
Column3 = nothing ' should be 01/01/0001
If you look at the values in DataRow, Column 1,2 & 3 they do not reflect the defaults, although they all have some value in them (particularly true with DateTime)

3) Now, using a DataAdapter for the table add the DataRow to the DataSource.
It fails everytime with a message like: "Cannot write null to non-nullable
Column1".

4) If you manually set the DataRow columns (1,2,3) to their default values, it works every time.

What does that mean? Nothing does not work. Very frustrating.

Please advise.

Bob Day

Nov 20 '05 #2
I really don't understand the distinction you are tyring to make. Below is
the documentation.
It says that dim x as boolean = nothing, then x should have a value of
False, the same as if you did dim x as boolean = false.

In other words, these two sould produce the same value:
1) dim x as boolean = nothing
2) dim x as boolean = false

1 fails, 2 writes to a datasource just fine.

Default, as defined below, is the default of the data type, not <NULL>.

Please help me understand.

Bob

Documentation for help:
The Nothing keyword represents the default value of any data type. Assigning
Nothing to a variable sets it to the default value for its declared type. If
that type contains variable members, they are all set to their default
values. The following example illustrates this:

Public Structure MyStruct
Public Name As String
Public Number As Short
End Structure
Dim S As MyStruct, I As Integer, B As Boolean
S = Nothing ' Sets S.Name to Nothing, S.Number to 0.
I = Nothing ' Sets I to 0.
B = Nothing ' Sets B to False.If the variable is of a reference type -
that is, an object variable - Nothing means the variable is not associated
with any object. For example:

Dim MyObject As Object
MyObject = Nothing ' No object currently referred to.When you assign
Nothing to an object variable, it no longer refers to any object instance.
If the variable had previously referred to an instance, setting it to
Nothing does not terminate the instance itself. The instance is terminated,
and the memory and system resources associated with it are released, only
after the garbage collector detects there are no active references
remaining.

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Bob, setting the column to nothing does just that, it sets it to the default value of the object not to the default value that you assigned the object.

Column1 = nothing

Then try referencing Column1 will give you a null reference exception. All of those columns are now null, so if you try adding a row with them in it,
you'll get that exception.

The confusion comes from the word Default. Any given column can havea
default value that you assign. The Default value for a Column is nothing,
meaning that you haven't defined it yet.

Try setting Column2 to string.Empty for instance, Column1 to 0 and column3
to 01/01/0001 and it will work. Also, since you set them to nothing, they
very well may be garbage collected and cease to exist.

HTH,

Bill
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
VS 2003

The documentation says " Nothing keyword represents the default value of

any
data type" this is simply not true and causing a lot of problems.

1) Consider an SQL table of 3 columns:

Column1 bit no nulls
Column2 string no nulls
Column3 DateTime no nulls

2) then, set each column in a DataSet, DataRowto nothing
Column1 = nothing ' should be 0 false
Column2 = nothing ' should be string.empty
Column3 = nothing ' should be 01/01/0001
If you look at the values in DataRow, Column 1,2 & 3 they do not reflect

the
defaults, although they all have some value in them (particularly true

with
DateTime)

3) Now, using a DataAdapter for the table add the DataRow to the

DataSource.

It fails everytime with a message like: "Cannot write null to non-nullable Column1".

4) If you manually set the DataRow columns (1,2,3) to their default

values,
it works every time.

What does that mean? Nothing does not work. Very frustrating.

Please advise.

Bob Day


Nov 20 '05 #3
You cannot test a Boolean, Integer DateTme or any other "Value" type for
Nothing... You must use a reference type if you want to check for Nothing...
A Boolean datatypes initial value, hence the term "Value Type" is False and
Integer is 0 a DataTime is 01/01/0001...
Try this
Dim bol As Boolean

If bol Is Nothing Then

End If

Dim str As String

If str Is Nothing Then

End If

The second test does not produce an error because String is a "Reference
Type"

Does that help....?
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
I really don't understand the distinction you are tyring to make. Below is the documentation.
It says that dim x as boolean = nothing, then x should have a value of
False, the same as if you did dim x as boolean = false.

In other words, these two sould produce the same value:
1) dim x as boolean = nothing
2) dim x as boolean = false

1 fails, 2 writes to a datasource just fine.

Default, as defined below, is the default of the data type, not <NULL>.

Please help me understand.

Bob

Documentation for help:
The Nothing keyword represents the default value of any data type. Assigning Nothing to a variable sets it to the default value for its declared type. If that type contains variable members, they are all set to their default
values. The following example illustrates this:

Public Structure MyStruct
Public Name As String
Public Number As Short
End Structure
Dim S As MyStruct, I As Integer, B As Boolean
S = Nothing ' Sets S.Name to Nothing, S.Number to 0.
I = Nothing ' Sets I to 0.
B = Nothing ' Sets B to False.If the variable is of a reference type -
that is, an object variable - Nothing means the variable is not associated
with any object. For example:

Dim MyObject As Object
MyObject = Nothing ' No object currently referred to.When you assign
Nothing to an object variable, it no longer refers to any object instance.
If the variable had previously referred to an instance, setting it to
Nothing does not terminate the instance itself. The instance is terminated, and the memory and system resources associated with it are released, only
after the garbage collector detects there are no active references
remaining.

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Bob, setting the column to nothing does just that, it sets it to the

default
value of the object not to the default value that you assigned the object.

Column1 = nothing

Then try referencing Column1 will give you a null reference exception.

All
of those columns are now null, so if you try adding a row with them in it, you'll get that exception.

The confusion comes from the word Default. Any given column can havea
default value that you assign. The Default value for a Column is nothing, meaning that you haven't defined it yet.

Try setting Column2 to string.Empty for instance, Column1 to 0 and column3 to 01/01/0001 and it will work. Also, since you set them to nothing, they very well may be garbage collected and cease to exist.

HTH,

Bill
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
VS 2003

The documentation says " Nothing keyword represents the default value
of any
data type" this is simply not true and causing a lot of problems.

1) Consider an SQL table of 3 columns:

Column1 bit no nulls
Column2 string no nulls
Column3 DateTime no nulls

2) then, set each column in a DataSet, DataRowto nothing
Column1 = nothing ' should be 0 false
Column2 = nothing ' should be string.empty
Column3 = nothing ' should be 01/01/0001
If you look at the values in DataRow, Column 1,2 & 3 they do not
reflect the
defaults, although they all have some value in them (particularly true

with
DateTime)

3) Now, using a DataAdapter for the table add the DataRow to the

DataSource.

It fails everytime with a message like: "Cannot write null to

non-nullable Column1".

4) If you manually set the DataRow columns (1,2,3) to their default

values,
it works every time.

What does that mean? Nothing does not work. Very frustrating.

Please advise.

Bob Day



Nov 20 '05 #4
Bob:

Look at your the documentation you posted:

' No object currently referred to.When you assign
Nothing to an object variable, it no longer refers to any object instance.>>

Ok, so you have an instance of a column and set it to nothing ..."it no
longer refers to any object instance" If it doesn't refer to any instance
object, then how could you determine its type?

Let me state it more pragmatically....If you want to use the object,
determine it's type, set it's value etc...setting it to nothing will cause
problems.
Now I ask you... Are reference types, ie DataColumns and Value Types
Structs, treated the same when set to nothing? Therein lyes the answer to
your question.

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:#$*************@TK2MSFTNGP10.phx.gbl...
I really don't understand the distinction you are tyring to make. Below is the documentation.
It says that dim x as boolean = nothing, then x should have a value of
False, the same as if you did dim x as boolean = false.

In other words, these two sould produce the same value:
1) dim x as boolean = nothing
2) dim x as boolean = false

1 fails, 2 writes to a datasource just fine.

Default, as defined below, is the default of the data type, not <NULL>.

Please help me understand.

Bob

Documentation for help:
The Nothing keyword represents the default value of any data type. Assigning Nothing to a variable sets it to the default value for its declared type. If that type contains variable members, they are all set to their default
values. The following example illustrates this:

Public Structure MyStruct
Public Name As String
Public Number As Short
End Structure
Dim S As MyStruct, I As Integer, B As Boolean
S = Nothing ' Sets S.Name to Nothing, S.Number to 0.
I = Nothing ' Sets I to 0.
B = Nothing ' Sets B to False.If the variable is of a reference type -
that is, an object variable - Nothing means the variable is not associated
with any object. For example:

Dim MyObject As Object
MyObject = Nothing ' No object currently referred to.When you assign
Nothing to an object variable, it no longer refers to any object instance.
If the variable had previously referred to an instance, setting it to
Nothing does not terminate the instance itself. The instance is terminated, and the memory and system resources associated with it are released, only
after the garbage collector detects there are no active references
remaining.

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Bob, setting the column to nothing does just that, it sets it to the

default
value of the object not to the default value that you assigned the object.

Column1 = nothing

Then try referencing Column1 will give you a null reference exception.

All
of those columns are now null, so if you try adding a row with them in it, you'll get that exception.

The confusion comes from the word Default. Any given column can havea
default value that you assign. The Default value for a Column is nothing, meaning that you haven't defined it yet.

Try setting Column2 to string.Empty for instance, Column1 to 0 and column3 to 01/01/0001 and it will work. Also, since you set them to nothing, they very well may be garbage collected and cease to exist.

HTH,

Bill
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
VS 2003

The documentation says " Nothing keyword represents the default value
of any
data type" this is simply not true and causing a lot of problems.

1) Consider an SQL table of 3 columns:

Column1 bit no nulls
Column2 string no nulls
Column3 DateTime no nulls

2) then, set each column in a DataSet, DataRowto nothing
Column1 = nothing ' should be 0 false
Column2 = nothing ' should be string.empty
Column3 = nothing ' should be 01/01/0001
If you look at the values in DataRow, Column 1,2 & 3 they do not
reflect the
defaults, although they all have some value in them (particularly true

with
DateTime)

3) Now, using a DataAdapter for the table add the DataRow to the

DataSource.

It fails everytime with a message like: "Cannot write null to

non-nullable Column1".

4) If you manually set the DataRow columns (1,2,3) to their default

values,
it works every time.

What does that mean? Nothing does not work. Very frustrating.

Please advise.

Bob Day



Nov 20 '05 #5
Bob: The whole distinction, is this...are DataColumns Reference types or
Value Types? What type is a Struct that you make mention of?
"William Ryan" <do********@nospam.comcast.net> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Bob, setting the column to nothing does just that, it sets it to the default value of the object not to the default value that you assigned the object.

Column1 = nothing

Then try referencing Column1 will give you a null reference exception. All of those columns are now null, so if you try adding a row with them in it,
you'll get that exception.

The confusion comes from the word Default. Any given column can havea
default value that you assign. The Default value for a Column is nothing,
meaning that you haven't defined it yet.

Try setting Column2 to string.Empty for instance, Column1 to 0 and column3
to 01/01/0001 and it will work. Also, since you set them to nothing, they
very well may be garbage collected and cease to exist.

HTH,

Bill
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
VS 2003

The documentation says " Nothing keyword represents the default value of

any
data type" this is simply not true and causing a lot of problems.

1) Consider an SQL table of 3 columns:

Column1 bit no nulls
Column2 string no nulls
Column3 DateTime no nulls

2) then, set each column in a DataSet, DataRowto nothing
Column1 = nothing ' should be 0 false
Column2 = nothing ' should be string.empty
Column3 = nothing ' should be 01/01/0001
If you look at the values in DataRow, Column 1,2 & 3 they do not reflect

the
defaults, although they all have some value in them (particularly true

with
DateTime)

3) Now, using a DataAdapter for the table add the DataRow to the

DataSource.

It fails everytime with a message like: "Cannot write null to non-nullable Column1".

4) If you manually set the DataRow columns (1,2,3) to their default

values,
it works every time.

What does that mean? Nothing does not work. Very frustrating.

Please advise.

Bob Day


Nov 20 '05 #6
Amen:

Since it's a reference type, it needs to be treated as one. Structs, Enums
etc are value types. DataColumns are reference types.
"alien2_51" <da********@n.o.s.p.a.m.monacocoach.com> wrote in message
news:es**************@TK2MSFTNGP09.phx.gbl...
You cannot test a Boolean, Integer DateTme or any other "Value" type for
Nothing... You must use a reference type if you want to check for Nothing... A Boolean datatypes initial value, hence the term "Value Type" is False and Integer is 0 a DataTime is 01/01/0001...
Try this
Dim bol As Boolean

If bol Is Nothing Then

End If

Dim str As String

If str Is Nothing Then

End If

The second test does not produce an error because String is a "Reference
Type"

Does that help....?
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
I really don't understand the distinction you are tyring to make. Below is
the documentation.
It says that dim x as boolean = nothing, then x should have a value of
False, the same as if you did dim x as boolean = false.

In other words, these two sould produce the same value:
1) dim x as boolean = nothing
2) dim x as boolean = false

1 fails, 2 writes to a datasource just fine.

Default, as defined below, is the default of the data type, not <NULL>.

Please help me understand.

Bob

Documentation for help:
The Nothing keyword represents the default value of any data type.

Assigning
Nothing to a variable sets it to the default value for its declared type. If
that type contains variable members, they are all set to their default
values. The following example illustrates this:

Public Structure MyStruct
Public Name As String
Public Number As Short
End Structure
Dim S As MyStruct, I As Integer, B As Boolean
S = Nothing ' Sets S.Name to Nothing, S.Number to 0.
I = Nothing ' Sets I to 0.
B = Nothing ' Sets B to False.If the variable is of a reference type -
that is, an object variable - Nothing means the variable is not associated with any object. For example:

Dim MyObject As Object
MyObject = Nothing ' No object currently referred to.When you assign
Nothing to an object variable, it no longer refers to any object instance. If the variable had previously referred to an instance, setting it to
Nothing does not terminate the instance itself. The instance is terminated,
and the memory and system resources associated with it are released, only after the garbage collector detects there are no active references
remaining.

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Bob, setting the column to nothing does just that, it sets it to the

default
value of the object not to the default value that you assigned the

object.
Column1 = nothing

Then try referencing Column1 will give you a null reference exception.

All
of those columns are now null, so if you try adding a row with them in it, you'll get that exception.

The confusion comes from the word Default. Any given column can havea
default value that you assign. The Default value for a Column is nothing, meaning that you haven't defined it yet.

Try setting Column2 to string.Empty for instance, Column1 to 0 and column3 to 01/01/0001 and it will work. Also, since you set them to nothing, they very well may be garbage collected and cease to exist.

HTH,

Bill
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
> VS 2003
>
> The documentation says " Nothing keyword represents the default value of
any
> data type" this is simply not true and causing a lot of problems.
>
> 1) Consider an SQL table of 3 columns:
>
> Column1 bit no nulls
> Column2 string no nulls
> Column3 DateTime no nulls
>
> 2) then, set each column in a DataSet, DataRowto nothing
> Column1 = nothing ' should be 0 false
> Column2 = nothing ' should be string.empty
> Column3 = nothing ' should be 01/01/0001
> If you look at the values in DataRow, Column 1,2 & 3 they do not reflect the
> defaults, although they all have some value in them (particularly

true with
> DateTime)
>
> 3) Now, using a DataAdapter for the table add the DataRow to the
DataSource.
>
> It fails everytime with a message like: "Cannot write null to

non-nullable
> Column1".
>
> 4) If you manually set the DataRow columns (1,2,3) to their default
values,
> it works every time.
>
> What does that mean? Nothing does not work. Very frustrating.
>
> Please advise.
>
> Bob Day
>
>
>



Nov 20 '05 #7

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

Similar topics

12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
8
by: Steven Bethard | last post by:
Sorry if this is a repost -- it didn't appear for me the first time. So I was looking at the Language Reference's discussion about emulating container types, and nowhere in it does it mention...
27
by: Dave Anderson | last post by:
Last September, some of us engaged in a discussion of freeing resources in ASP scripts written in JScript. It can be seen here: http://tinyurl.com/2flzt I recently read Eric Lippert's article on...
15
by: Generic Usenet Account | last post by:
While I have a very good feel for how inlining works, I fail to see how in the world inlining can work if the inlined function is not described "in place" in a header file, but rather defined in a...
1
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if...
11
by: Michi Henning | last post by:
Hi, I'm using a blocking Select() call on a socket with a timeout value of -1. I'd expect the call to block indefinitely, but it doesn't. When I use Poll() instead, a timeout of -1 works fine...
2
by: Oenone | last post by:
In our applications, we use the special value of DateTime.MinValue to represent "null dates" throughout all our code. We recently ran into an issue where we wanted an optional date parameter for a...
25
by: Peter Michaux | last post by:
Hi, I'm thinking about code minimization. I can think of a few places where whitespace matters a + ++b a++ + b a - --b a-- -b when a line ends without a semi-colon in which case the new...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.