John Oliver (UK)MSP, VSIP

 

Hi,

Why is vbNull not Chr(0) instead of "1"  or = System.DBNull.Value

See>>

Dim s As String = Chr(0)

MsgBox(" String 's' is = " & s)

or>>

Can yourselves not make it the default value for a string instead in future versions of Visual Studio please

Dim s As String = System.DBNull.Value.ToString

MsgBox(" String 's' is = " & s)

 I presume Chr(0) = System.DBNull.Value.ToString

 

See also http://asciitable.com/ about Chr(0)

 

Regards,

S_DS

 




Re: Visual Basic Language To Microsoft staff about vbNull.

Christian Liensberger

You are mixing stuff up here!

DBNull.Value is something completely different. That is NULL in the database (means NULL of a member of a relation). If you want to set a string to NULL in VB.NET, you need to use Nothing (keyword).

The vbNull constant is inteded to be returned by the VarType function: see MSDN documentation.






Re: Visual Basic Language To Microsoft staff about vbNull.

Spidermans_DarkSide

 Christian Liensberger - MSP wrote:

You are mixing stuff up here!

DBNull.Value is something completely different. That is NULL in the database (means NULL of a member of a relation). If you want to set a string to NULL in VB.NET, you need to use Nothing (keyword).

<edit by S_DS> Why not the following >> Dim myString="" 

</edit>

The vbNull constant is inteded to be returned by the VarType function: see MSDN documentation.

 I thought Null is Chr(0) and that

 NOTHING meant literally NOTHING at all!! ( i.e. it doesn't reference anything )

 In SQL Enterprise Manager or in MS-Access you can't set a string value to NOTHING!!

 That is because you can't srore NOTHING in a string field  but you can store NULL.

 As i said see CHR(0) in http://asciitable.com

A NULL string i.e. "" is not the same as NOTHING

 

Regards,

S_DS

 






Re: Visual Basic Language To Microsoft staff about vbNull.

Christian Liensberger - MSP

but the string ending sing \0 is different then DBNull.Value. You can set a row NULL in the SQL Management Studio. And that NULL is DBNull.Value. If you work with parameters in ADO.NET command objects, you need to set the value to DBNull.Value to have NULL inserted in the database. That's because Nothing, DBNull.Value and \0 isn't the same.

Nothing = a pointer to nothing
DBNull.Value = special value that means that the database (column, row) should be null.
\0 = String determinator telling that the string ends here.

string has a method returning you an empty string - in fact it is just a \0 that is returned (string.Empty). string.IsNullOrEmpty for example checks if the string is Nothing or \0.






Re: Visual Basic Language To Microsoft staff about vbNull.

Spidermans_DarkSide

 Christian Liensberger - MSP wrote:

but the string ending sing \0 is different then DBNull.Value. You can set a row NULL in the SQL Management Studio. And that NULL is DBNull.Value. If you work with parameters in ADO.NET command objects, you need to set the value to DBNull.Value to have NULL inserted in the database. That's because Nothing, DBNull.Value and \0 isn't the same.

Nothing = a pointer to nothing
DBNull.Value = special value that means that the database (column, row) should be null.
\0 = String determinator telling that the string ends here.

string has a method returning you an empty string - in fact it is just a \0 that is returned (string.Empty). string.IsNullOrEmpty for example checks if the string is Nothing or \0.

How is DBNull.Value stored in a database then

How can you have a pointer to NOTHING ( sit still )....LOL

What is the difference between an EMPTY and a NULL string then

emptyString = ""   'also = CHR(0)

nullString = NOTHING '

 If so i'm still asking Microsoft why not make default value of STRING = "" then

Is DBNull.Value  DataBaseNullValue then

 I now know more about what NOTHING and CHR(0) are, thanks to you.

 

Regards,

S_DS

 






Re: Visual Basic Language To Microsoft staff about vbNull.

Christian Liensberger - MSP

Well NULL (Nothing, null, nil) is just a pointer to the 0 address. That's how it went originally. an empty string is "", which is a string that consists only of \0. A null string is when the reference of the string variable points to null. For example "".Trim() works on the empty string. which doesn't work if the variable is set to null.

String is a reference type in .NET - not a struct like for example Int32 (int), Int16 (short), Int64 (long). Structs are value types - they inherit from ValueType. They can't be null, because they are managed on the stack. String, as it is a reference type, is managed on the heap and can be null. By default all reference types are initialized with NULL. That's why string is initalized with NULL.

If you want your strings to be initialized with "" you need to do it by hand.

string foo = string.Empty; // or string foo = "";

Although it's better to have it initialized with null. That uses less memory and it's easier to check if a string has been initialized already. Makes algorithms easier.

EDIT: DBNull.Value is a special value that is understood by the ADO.NET providers to conver them to the database null value. Each database has an own value (internally) that represents null. The ADO.NET provider takes care for you to convert DBNull.Value to the database null. It is converted to the actual database NULL for you and converted back, once you load a record from database.