VS 2003, vb.net, sql native (MSDE)...
I have railed against the inconsistency of the Nothing key word. The
documentation says is will assign a default value for any datatype...well,
not exactly. Here are 2 more examples:
Example 1) dim x as string = nothing, the value of x is nothing (instead of
string.empty). When you add a row to SQL, the column with the value of X
will fail in a table that does not allow nulls because Nothing is translated
to DBNull. So, the default value of a string is DBNull? That is not very
intuitive.
Example 2) dim y as Boolean = nothing, the value of x is false (which makes
sense). This writes to an SQL table fine as 0 (false)
However, consider a Boolean column datatype, DataColumn.defaultvalue =
nothing. When you add a row to SQL, the Boolean column with the value of
..defaultvalue = nothing will fail in a table that does not allow nulls
because Nothing is translated to DBNull (instead of false). So, the
..defaultvalue of a Boolean is DBNull? That is not very intuitive.
The above are replicatable every time.
These inconsistencies with the documentation about Nothing are frustrating
and time consuming. Someone should spend the time to make Nothing
consistent in a future release - it would be appreciated.
Bob Day 26 6018
I don't know if I would say its not "intuitive" in fact, I think it very
much is.
There is a major difference between an empty string and a null value. As
well as understanding the difference between Nothing and and empty value.
Nothing says it doesn't exist, Empty says it exists but with no value. See
the difference?
Also, there are many more applications that don't use DB's, where an Empty
is different from a Null. To predict that within the language would be
impossible. So the option is given to the programmer.
Hope it helps. I know it doesn't make sense, but its really understanding
what an object is vs. a value.
-CJ
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... VS 2003, vb.net, sql native (MSDE)...
I have railed against the inconsistency of the Nothing key word. The documentation says is will assign a default value for any
datatype...well, not exactly. Here are 2 more examples:
Example 1) dim x as string = nothing, the value of x is nothing (instead
of string.empty). When you add a row to SQL, the column with the value of X will fail in a table that does not allow nulls because Nothing is
translated to DBNull. So, the default value of a string is DBNull? That is not very intuitive.
Example 2) dim y as Boolean = nothing, the value of x is false (which
makes sense). This writes to an SQL table fine as 0 (false)
However, consider a Boolean column datatype, DataColumn.defaultvalue = nothing. When you add a row to SQL, the Boolean column with the value of .defaultvalue = nothing will fail in a table that does not allow nulls because Nothing is translated to DBNull (instead of false). So, the .defaultvalue of a Boolean is DBNull? That is not very intuitive.
The above are replicatable every time.
These inconsistencies with the documentation about Nothing are frustrating and time consuming. Someone should spend the time to make Nothing consistent in a future release - it would be appreciated.
Bob Day
Bob,
Did you try this?
If Nothing = String.Empty Then
MessageBox.Show("empty")
End If
I would not say it is all direct clear with "Nothing" but for me the
inconsequenties in the SQL syntax are worser.
Cor
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader21.wxs.nl... Bob,
Did you try this? If Nothing = String.Empty Then MessageBox.Show("empty") End If
I would not say it is all direct clear with "Nothing" but for me the inconsequenties in the SQL syntax are worser.
worser?????????
is that like having the proper strategery?
Cor
Hi CJ,
That's better.
That's worse.
It shows that English is maybe not the best language to use with
programming.
It seems to be a not consistent language.
;-)
Cor
Nothing is the default (uninitialized) value for an *object* type. The
default (uninitialized) value for a *value* type is up to the language.
A string is an object type, so you can set it to nothing. String.Empty is
not nothing (in some implementations it contains 1 character - the null
character or Chr(0) to signify the end of the string). In most databases, an
empty string is also treated differently than Null.
Boolean, Integer, Floating Point variables etc. are value types and so
cannot be set to nothing. Instead they are set to the default value for that
type (0, False etc.)
If you need empty strings to be placed in your table, declare them as
Dim szMyString as String = ""
HTH,
Trev.
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:#a**************@TK2MSFTNGP09.phx.gbl... VS 2003, vb.net, sql native (MSDE)...
I have railed against the inconsistency of the Nothing key word. The documentation says is will assign a default value for any
datatype...well, not exactly. Here are 2 more examples:
Example 1) dim x as string = nothing, the value of x is nothing (instead
of string.empty). When you add a row to SQL, the column with the value of X will fail in a table that does not allow nulls because Nothing is
translated to DBNull. So, the default value of a string is DBNull? That is not very intuitive.
Example 2) dim y as Boolean = nothing, the value of x is false (which
makes sense). This writes to an SQL table fine as 0 (false)
However, consider a Boolean column datatype, DataColumn.defaultvalue = nothing. When you add a row to SQL, the Boolean column with the value of .defaultvalue = nothing will fail in a table that does not allow nulls because Nothing is translated to DBNull (instead of false). So, the .defaultvalue of a Boolean is DBNull? That is not very intuitive.
The above are replicatable every time.
These inconsistencies with the documentation about Nothing are frustrating and time consuming. Someone should spend the time to make Nothing consistent in a future release - it would be appreciated.
Bob Day
"CJ Taylor" <no****@blowgoats.com> scripsit: There is a major difference between an empty string and a null value. As
In some DBMS strings of zero length (empty strings) are treated as
NULL. That's IMO very unintuitive, because there is a semantical
difference beteen a zero-length string an a null value. NULL means
"unknown" to me, a zero length string means that the information is "".
;-)
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
"Cor" <no*@non.com> scripsit: Did you try this? If Nothing = String.Empty Then MessageBox.Show("empty") End If
'String.Empty' is a zero-length string, "". The default value of a
string is "" too.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
"Cor" <no*@non.com> schrieb: That's better. That's worse. It shows that English is maybe not the best language to use with programming. It seems to be a not consistent language.
Latin would be better...
;-)
--
Herfried K. Wagner
MVP · VB Classic, VB.NET http://www.mvps.org/dotnet
Hi Herfried,
You maybe are kidding and I don't know it at all, but I sometimes think that
is true.
Is the modern Latin consistent, it has been for years the language of the
scienctific?
Cor
There is no such thing as 'modern Latin'.
"Cor" <no*@non.com> wrote in message
news:3f**********************@reader21.wxs.nl... Hi Herfried, You maybe are kidding and I don't know it at all, but I sometimes think
that is true. Is the modern Latin consistent, it has been for years the language of the scienctific? Cor
Stephany,
Are you defiantly sure of that, do you think that the first Romans did speak
the same language as the now official language from the country Vatican.
I really don't know it. (I have putted the word "modern" in to give an
accent about the official used scientific Latin, but maybe I had better done
to write it in that way.)
Cor
The Latin language that is spoken in the Vatican and by scholars in various
universities is the same Latin as was spoken by the Romans.
In recent years new 'latin' words have been coined to represent modern words
and phrases like telephonium albo televisifico coniunctum for video
telephone, tempus maximae frequentiae for rush hour, publicae securitatis
custos internationalis for Interpol and officium foederatum vestigatorium
for FBI. This, by no means amounts to 'modernising' the language.
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader21.wxs.nl... Stephany, Are you defiantly sure of that, do you think that the first Romans did
speak the same language as the now official language from the country Vatican. I really don't know it. (I have putted the word "modern" in to give an accent about the official used scientific Latin, but maybe I had better
done to write it in that way.) Cor
"Stephany Young" <as******@mona.lisa> schrieb: The Latin language that is spoken in the Vatican and by scholars in various universities is the same Latin as was spoken by the Romans.
I think the pronounciation may be slightly different...
;-)))
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
One of the beauties of Latin is that, because of the 'strictness' of the
language there is only one way to pronounce any given word. With Latin there
are no grey areas and there is no room for variation.
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl... "Stephany Young" <as******@mona.lisa> schrieb: The Latin language that is spoken in the Vatican and by scholars in various universities is the same Latin as was spoken by the Romans.
I think the pronounciation may be slightly different...
;-)))
-- Herfried K. Wagner MVP · VB Classic, VB.NET <http://www.mvps.org/dotnet>
> 'String.Empty' is a zero-length string, "". The default value of a string is "" too.
I don't agree that the default value of a string in VB.net is "". A string
is an object, so it's default value is Nothing (Unlike VB6).
Take the following example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim szTest as String
Debug.Write(szTest) ' Writes nothing to the output
Debug.Write(Nothing) ' Writes nothing to the output
Debug.Write(szTest.Length) ' Raises NullReferenceException
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The third Debug.Write will raise a NullReferenceException as the default
value of szTest is Nothing. If you look at szTest in the watch window, it's
value is "Nothing"
The reason why no error is raised on the first two calls to Debug.Write is
because Debug.Write can take Nothing as a parameter.
If you declared your string as:
Dim szTest as String = ""
Then the default value of that string would be "" as opposed to Nothing.
Sorry for being a stick in the mud ;-)
"Herfried K. Wagner [MVP]" <hi*******@m.gmx.at> wrote in message
news:zn**********@m.gmx.at... "Cor" <no*@non.com> scripsit: > Did you try this? If Nothing = String.Empty Then MessageBox.Show("empty") End If
'String.Empty' is a zero-length string, "". The default value of a string is "" too.
-- Herfried K. Wagner MVP · VB Classic, VB.NET <http://www.mvps.org/dotnet>
Codemonkey,
I take another approach (I come on this, because it was a question in this
newsgroup yesterday). A string is an array and as we are used to now, it is
an array of characters (in the past bytes, but now we have Unicode
characters).
How many characters are there in a string "" ?
Cor
"Stephany Young" <as******@mona.lisa> schrieb: One of the beauties of Latin is that, because of the 'strictness' of the language
An 'Option Strict On' language...
;-)
there is only one way to pronounce any given word. With Latin there are no grey areas and there is no room for variation.
ACK. Nevertheless, some letters can be pronounced differently, for example
"a" is pronounced in a different way by German speakers than by English
speakers. When I "spoke" Latin at school, I used the German pronounciation.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Hi Bob, So, the default value of a string is DBNull? That is not very intuitive.
<<
The default value of a string variable in VB .NET is Nothing, because String
is a reference type. What's happening is that your data access provider (the
component that controls the database connection) is translating Nothing to
Null, which means "unknown" in any proper RDBMS. This has nothing to do with
VB or .NET - it's just the way the data access component that you're using
works.
So, the .defaultvalue of a Boolean is DBNull? <<
The default value of a boolean variable in VB .NET is False, because Boolean
is a value type and a value type can't contain Nothing. However, a
DataColumn of type boolean *must* be able to have a default value of
Nothing, because the associated database column might allow Null as a valid
value.
Think about it - if a DataColumn of type boolean couldn't have a value of
Nothing, how would you be able to set the associated database column to
Null?
HTH,
Mark
--
Author of "Comprehensive VB .NET Debugging" http://www.apress.com/book/bookDisplay.html?bID=128
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:#a**************@TK2MSFTNGP09.phx.gbl...
VS 2003, vb.net, sql native (MSDE)...
I have railed against the inconsistency of the Nothing key word. The
documentation says is will assign a default value for any datatype...well,
not exactly. Here are 2 more examples:
Example 1) dim x as string = nothing, the value of x is nothing (instead of
string.empty). When you add a row to SQL, the column with the value of X
will fail in a table that does not allow nulls because Nothing is translated
to DBNull. So, the default value of a string is DBNull? That is not very
intuitive.
Example 2) dim y as Boolean = nothing, the value of x is false (which makes
sense). This writes to an SQL table fine as 0 (false)
However, consider a Boolean column datatype, DataColumn.defaultvalue =
nothing. When you add a row to SQL, the Boolean column with the value of
..defaultvalue = nothing will fail in a table that does not allow nulls
because Nothing is translated to DBNull (instead of false). So, the
..defaultvalue of a Boolean is DBNull? That is not very intuitive.
The above are replicatable every time.
These inconsistencies with the documentation about Nothing are frustrating
and time consuming. Someone should spend the time to make Nothing
consistent in a future release - it would be appreciated.
Bob Day
If you were allowed to learn Latin with any pronunciation other than the
correct one then your Latin teacher should be jailed.
An "a" in Latin is pronounced the same whether you come from Germany,
Timbuktu or Mars.
It is pronounced as the short "a" sound as in the English cat, axe, etc.
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:e0**************@tk2msftngp13.phx.gbl... "Stephany Young" <as******@mona.lisa> schrieb: One of the beauties of Latin is that, because of the 'strictness' of the language An 'Option Strict On' language...
;-)
there is only one way to pronounce any given word. With Latin there are no grey areas and there is no room for variation.
ACK. Nevertheless, some letters can be pronounced differently, for
example "a" is pronounced in a different way by German speakers than by English speakers. When I "spoke" Latin at school, I used the German
pronounciation. -- Herfried K. Wagner MVP · VB Classic, VB.NET <http://www.mvps.org/dotnet>
Cor,
As far as I know (not very far ;-) the number of characters in "" depends on
how the string is implemented. I haven't a clue how a string is implemented
internally in .net. I'd be happy if anybody wants to take the time and
expain it properly.
In older implementations when a string was an array of bytes (buffer), the
array might have 10 elements, but if the first character is Chr(0), then the
string should be treated as if it contained no characters i.e. Its size in
bytes would be 10, but its length in characters would be 0 (or 1 if the null
character is counted in the particular implementation).
"Cor" <no*@non.com> wrote in message
news:3f**********************@reader21.wxs.nl... Codemonkey, I take another approach (I come on this, because it was a question in this newsgroup yesterday). A string is an array and as we are used to now, it
is an array of characters (in the past bytes, but now we have Unicode characters).
How many characters are there in a string "" ?
Cor
Herfried,
Saterday night, but is the pronounce from the Italian character a (and our
part of Europe) different than from Latin?
I am curious.
Cor
Hello,
"Stephany Young" <as******@mona.lisa> schrieb: If you were allowed to learn Latin with any pronunciation other than the correct one then your Latin teacher should be jailed.
An "a" in Latin is pronounced the same whether you come from Germany, Timbuktu or Mars.
It is pronounced as the short "a" sound as in the English cat, axe, etc.
Thanks for the info---I didn't know that it's pronounced that way in
English.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
"Cor" <no*@non.com> schrieb: Saterday night, but is the pronounce from the Italian character a (and our part of Europe) different than from Latin?
The German "a" character is pronounced similar to the Latin "a" and the
Italian "a".
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Hi Bob,
I've stayed out of this interesting thread because every time that I've
visited, one or more messages gets deleted when I click on it. This is the
first time that I've seen the thread intact!!
I agree with your distaste of the word Nothing when used with ValueTypes.
I'd even go as far as saying that it should be illegal to assign Nothing to a
ValueType. I would much prefer the use of the word Default - but they're
already using that for Default Properties, dammit!
Just one example:
Dim Somewhere As Point = Nothing 'Nothing means centre or origin.
The above doesn't put Somewhere outside the designated space - it puts it
smack in the middle at {0, 0}. That's hardly Nothing (or perhaps I should say
nowhere).
But while it sounds stupid to assign Nothing to a Boolean or a Point, I
agree with everyone else that for objects it makes perfect sense for Nothing
to mean 'no object'. The default type for an object variable <is> 'no
object' - how could it be anything else? This has to include Strings, too, for
they are reference types.
With the database values it seems unintuitive because while a Boolean can
only have True or False, a Boolean database column can be DbNull, True or
False. But that's because of the shortcuts in talking about it. A Boolean
database column isn't, and <cannot be>, a Boolean. It sounds as if I'm talking
in contradictions but 'Boolean database column' is just a convenient way of
saying 'a database column that, if it contains <anything>, will contain a
Boolean'. Hence DbNull for when it doesn't.
That's my two centimes.
Regards,
Fergus
Hi Bob, There are 3 pieces VS 2003, VB.NET & MS SQL. All Microsoft; all latest
versions <<
Well, VS 2003 has no opinion on any of this - it's just an IDE. MS SQL, on
the other hand, is a superset of ANSI SQL, so the way in which database
nulls are handled is not controlled by MS at all - hence the discrepancy
that you see.
HTH,
Mark
--
Author of "Comprehensive VB .NET Debugging" http://www.apress.com/book/bookDisplay.html?bID=128
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:#A**************@TK2MSFTNGP10.phx.gbl...
Yes, I agree with all of that. My point, however, is that the documentation
around the word Nothing does not match what it does. That, in my book, is a
bug.
There are 3 pieces VS 2003, VB.NET & MS SQL. All Microsoft; all latest
versions. It is very hard to deal with these three pieces interpreting
Nothing differently, as they do. Dim x as Boolean = nothing is false in
VB.NET but translates to DBNull when a row is added to SQL. Does that make
any sense in any scenario? Not in my humble opinion.
Bob Day
"Mark Pearce" <ev**@bay.com> wrote in message
news:uo**************@tk2msftngp13.phx.gbl... Hi Bob, So, the default value of a string is DBNull? That is not very
intuitive. <<
The default value of a string variable in VB .NET is Nothing, because
String is a reference type. What's happening is that your data access provider
(the component that controls the database connection) is translating Nothing to Null, which means "unknown" in any proper RDBMS. This has nothing to do
with VB or .NET - it's just the way the data access component that you're using works. So, the .defaultvalue of a Boolean is DBNull? << The default value of a boolean variable in VB .NET is False, because
Boolean is a value type and a value type can't contain Nothing. However, a DataColumn of type boolean *must* be able to have a default value of Nothing, because the associated database column might allow Null as a
valid value.
Think about it - if a DataColumn of type boolean couldn't have a value of Nothing, how would you be able to set the associated database column to Null?
HTH,
Mark -- Author of "Comprehensive VB .NET Debugging" http://www.apress.com/book/bookDisplay.html?bID=128
"Bob Day" <Bo****@TouchTalk.net> wrote in message news:#a**************@TK2MSFTNGP09.phx.gbl... VS 2003, vb.net, sql native (MSDE)...
I have railed against the inconsistency of the Nothing key word. The documentation says is will assign a default value for any
datatype...well, not exactly. Here are 2 more examples:
Example 1) dim x as string = nothing, the value of x is nothing (instead
of string.empty). When you add a row to SQL, the column with the value of X will fail in a table that does not allow nulls because Nothing is
translated to DBNull. So, the default value of a string is DBNull? That is not very intuitive.
Example 2) dim y as Boolean = nothing, the value of x is false (which
makes sense). This writes to an SQL table fine as 0 (false)
However, consider a Boolean column datatype, DataColumn.defaultvalue = nothing. When you add a row to SQL, the Boolean column with the value of .defaultvalue = nothing will fail in a table that does not allow nulls because Nothing is translated to DBNull (instead of false). So, the .defaultvalue of a Boolean is DBNull? That is not very intuitive.
The above are replicatable every time.
These inconsistencies with the documentation about Nothing are frustrating and time consuming. Someone should spend the time to make Nothing consistent in a future release - it would be appreciated.
Bob Day This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Harlan Messinger |
last post by:
At http://www.gavelcade.com/tests/partial-child-recognition.html is an
illustration of an apparent inconsistency in the way the child selection
operator > is handled with respect to tables, rows,...
|
by: Marina |
last post by:
Here is the problem. If 2 different properties on the same (or different)
control are bound to the same data column, changing the Text property and
calling EndCurrentEdit discards the new value. ...
|
by: Jerzy Karczmarczuk |
last post by:
Gurus, before I am tempted to signal this as a bug, perhaps
you might convince me that it should be so. If I type
l=range(4)
l.extend()
l gives , what else...
On the other hand, try
|
by: Larry Woods |
last post by:
Look at this code:
Dim i As Integer = 0
Dim j As Integer = 5
If (j / i = 7) Or i = 0 Then
MessageBox.Show("In If")
Else
MessageBox.Show("In Else")
End If
|
by: codeman |
last post by:
Hi all
Lets say we have two tables:
Customer:
Customer_number : Decimal(15)
Name : Char(30)
Purchase:
Purchase_number : Decimal(15)
|
by: Francine.Neary |
last post by:
I am learning C, having fun with strings & pointers at the moment!
The following program is my solution to an exercise to take an input,
strip the first word, and output the rest. It works fine...
|
by: Francine.Neary |
last post by:
I'm finding it really hard to keep some of these things straight...
For example, fputs is to puts as fprintf is to printf, except that
fputs has the file handle at the end and fprintf at the...
|
by: Rahul Babbar |
last post by:
Hi All,
When could be the possible reasons that could make a database
inconsistent?
I was told by somebody that it could become inconsistent if you "
force all the applications to a close on...
|
by: johnthawk |
last post by:
In the below code setting cell to inconsistent sets entire column inconsistent (renderer).However, I need a third state off | on | inconsistent . How can I change one path->cell?
Any help...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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...
|
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...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
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...
| |