Gbolahan
Gbolahan

Reputation: 420

insert null into mysql using vb.net

Is there way to insert null into mysql from an empty text field in vb.net

thanks..

Upvotes: 0

Views: 4827

Answers (3)

osmarditto
osmarditto

Reputation: 53

If this is not working, please check whether the field is null allowed.

Using cmd As New OleDb.OleDbCommand()
//... set connection string etc

    cmd.Parameters.Add("myFieldName", OleDbType.VarWChar)
    cmd.Parameters("myFieldName").Value = DBNull.Value

//... etc

End Using

Upvotes: 0

nancy alajarmeh
nancy alajarmeh

Reputation: 131

Simply you may use the following as your query string:

Dim Query as String = "Update Table set Column = NULL Where ID = " & SomeTextBox.Text

You apply that also when you insert.

Upvotes: 0

hawbsl
hawbsl

Reputation: 16043

Assuming you are using ADO.NET, OleDb and parameters, you need to set the value to DBNull.Value

Example:

Using cmd As New OleDb.OleDbCommand()
//... set connection string etc

    cmd.Parameters.Add("myFieldName", OleDbType.VarWChar)
    cmd.Parameters("myFieldName").Value = DBNull.Value

//... etc

End Using

Upvotes: 2

Related Questions