MySQL - How in the world I check the NULL value of this guy?

I was trying to work on extracting information out from MySQL via ASP.NET. Since MySQL only provides the connector, and I can't really connect to MySQL from ASP.NET via simple configuration steps on the ASP.NET web form or web.config, I have to write my own class to do the job.

As it progressed, I found that MySQL behaves differently as compare to SQL Server in terms of handling NULL value. I could simply do a NULL checking on data return from SQL Server with the following syntax.

value = (data_table[column_name] == NULL ? NULL : data_table[column_name]);

So, since MySQL has provided us with a .NET connector, I would assume that the above would work as well; but sadly, it doesn't. Oh Dear, what has gone wrong with it? When I tried to debug the web form (yes, debugging a web form is possible in Visual Studio 2005), I found out that the NULL value is returned with '{}'. This is not NULL!!! So how should I do this? I was totally mad about this because if the syntax works for SQL Server, it should work for MySQL as well, so why in the world they don't make it that way?

Anyway, I know my complaint won't work so I tried to look from the Internet for any possible solution. I did a search on DBNull, since it was in the error message that being thrown out. I found out that DBNull can be used to determine the NULL value returned by MySQL, so I give it a try and it works. So instead of the usual syntax that I used, I have to replace the NULL like the following syntax.

value = (data_table["column_name"] = DBNull.Value ? NULL : data_table["column_name"]);

Problem solves, but yet it shows that it is very hard to work to integrate different tool together, and I'll be facing a lot of this situation again in the future, Oh Dear...

Comments

Popular posts from this blog

Yahoo! Messenger voice call & video call disabled, why?

Sport's Injuries - Treatment for bruises

Web Development: Disable, Validate, & Enable Buttons