0

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

thanks..

1
  • 1
    ADO.NET? LINQ to SQL? Entity framework? Commented Oct 11, 2010 at 9:34

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

im using vb.net, oledb and parameters myCommand.Parameters.AddWithValue("@parameter_name", DBNull.Value) Returns a .read error This one works though so I assume DBNull.Value isnt recognized by vb.net when passing to mysql myCommand.Parameters.AddWithValue("@parameter_name", "")
0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.