troubleshooting Question

How to insert null value into MySQL table column

Avatar of rpkhare
rpkhareFlag for India asked on
MySQL Server.NET ProgrammingC#
8 Comments1 Solution3571 ViewsLast Modified:
I attempted following codes to insert NULL into one of the columns of a table in MySQL database. It is not taking either way.

In Method 1, it is displaying error:

Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'double?'

In Method 2, it is displaying error:

Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'double?'      

I cannot use the parameterized way. I want to use the query this way itself. I am using Visual Studio 2005 Windows Forms.

Method 1:
 
string InsertQuery = String.Format("INSERT INTO TABLE1 VALUES ({0})", (nTypeID == null) ? "NULL" : nTypeId);
 
Method 2:
string InsertQuery = String.Format("INSERT INTO TABLE1 VALUES ({0})", (nTypeID == null) ? DBNull.Value : nTypeId);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros