How to set Varchar field to NULL in VB.net 2005?

db , vb.net United States
  • 13 years ago

    Hi,
    I have a database table that contains a varchar(Data type)  columns that allows Null values.
    How do I programmatically write a Null value  to the database for example in order to "insert " an  data.

     ex:

    If Trim(adata(1)) = "" Then

    strName = "Null"

    Else

    strName = Trim(adata(1))

    End If

    above code will work for datatype length >=4 .

    if datatype length <4  above code is not working please advise me

    Thanks in advance.

  • 13 years ago

    If memory serves me correctly something like "DbNull.Value" should do the trick.

    "If a database field has missing data, you can use the DBNull.Value property to explicitly assign a DBNull object value to the field. However, most data providers do this automatically." [http://msdn2.microsoft.com/en-us/library/system.dbnull.value.aspx]

    Joe 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous