MySQL: Insert null values?

H

hellrazor

Hi there,

I have the following INSERT statement:

fieldOne is of type int
fieldTwo is of type date

In MySQL, both are allowed to hold null values.

Now, I try to insert regular data into it:

INSERT INTO myTable (fieldOne,fieldTwo) VALUES(3,'2004-05-18')

NO problem there.

But what is the format for inserting null values?

I tried the following:

nullValue = Nothing

"INSERT INTO myTable (fieldOne,fieldTwo) VALUES(" & nullValue & "," &
nullValue & ")"


I get the following error when I try to submit the query:

ERROR [42000] [MySQL][ODBC 3.51 Driver][mysqld-4.0.18-max-debug]You have
an error in your SQL syntax. Check the manual that corresponds to your
MySQL server version for the right syntax to use near ',,)' at line 1



Thanks in advance!
 
A

Armin Zingler

hellrazor said:
"INSERT INTO myTable (fieldOne,fieldTwo) VALUES(" & nullValue & "," &
nullValue & ")"

"...VALUES (NULL, NULL)..."

But, this question is neither related to ASP.Net, nor to the VB.Net
language. There's an ADO.Net group: microsoft.public.dotnet.framework.adonet

You should consider using the Parameters property of the Command object you
use to execute the Insert statment. You can assign DBNull.Value to the
Parameter value, and the right SQL string is built by the Command object.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top