Page 1 of 1
					
				DataTable IsNull() Returns True on zero length strings
				Posted: Thu  30 Aug 2007 22:59
				by garychin
				I have a column of type TEXT and I do a select on that column using either MySqlDataReader to get a reader or MySqlDataAdapter to fill a DataTable, The value returned is a zero length string, but using the reader's IsDBNull(0) and the datatable's method IsNull(0) returns true.  They should return false, and only true when NULL is actually being stored in the database.  Is there a fix for this or configuration option on the corelab driver to differentiate between these two cases?
Thanks for the help.
			 
			
					
				
				Posted: Fri  31 Aug 2007 09:02
				by Alexey
				Which version of MyDirect .NET do you use?
Which method of MySqlDataReader do you use to get value of that column?
			 
			
					
				
				Posted: Fri  31 Aug 2007 15:29
				by garychin
				I am using version 4.0.13.0 of Corelab.MySql.dll and 4.0.11.0 of Corelab.Data.dll.  
Here is an example, where column1 has type TEXT.  The if statements evaluate to true for zero length strings and null values. It should only happen for Null values.  I also wrote statements how I am accessing the data below each if statement in the case of DataTable and MySqlDataReader.  Is there a fix for this problem I am having?
            MySqlConnection conn = (MySqlConnection)GetConnection();
            MySqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "Select column1 FROM table1";
            
            MySqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                if (reader.IsDBNull(0))
                    MessageBox.Show("Found Null Value");
                string temp = reader.GetString(0);
            }
            reader.Close();
            MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            dataAdapter.Fill(dt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows.IsNull(0))
                    MessageBox.Show("Found Null Value");
                string temp = dt.Rows.ItemArray[0].ToString();
            }
Thanks again.
			 
			
					
				
				Posted: Mon  03 Sep 2007 07:20
				by Alexey
				This is a designed behaviour of MyDirect .NET.
Right decision is to use IsDBNull method first, like you did.
			 
			
					
				
				Posted: Tue  04 Sep 2007 19:55
				by garychin
				It seems that IsDBNull and IsNull methods evaluated to true for zero length string values only on embedded databases.  When I am running IsDBNull and IsNull on zero length strings on a regular MySQL instance they return false.  So the MyDirect.NET driver does not have consistent behavior in regard to zero length strings for embedded databases and a regular non-embedded MySQL instance.  Returning false for zero length strings, the way it works in the non-embedded MySQL instance, is desirable for my situation, but I need to use an embedded database.  Can you make the behavior consistent across embedded and non-embedded databases or explain why it cannot be this way and give me a workaround for the embedded database.  Thank you for your prompt replies.
			 
			
					
				
				Posted: Wed  05 Sep 2007 11:18
				by Alexey
				We will investigate this problem and probably fix it.
Look forward to hearing from me soon.
			 
			
					
				
				Posted: Thu  06 Sep 2007 11:10
				by Alexey
				This problem is fixed.
Look forward to the next build.
			 
			
					
				
				Posted: Thu  06 Sep 2007 17:47
				by garychin
				Thank you very much.
			 
			
					
				
				Posted: Mon  10 Sep 2007 15:33
				by garychin
				I tested the new build 4.20.18, and this problem is fixed for a regular MySql instance, however embedded database connections (when setting Embedded=true; in the connection string) still causes IsNull to evaluate to true for zero length strings.
			 
			
					
				
				Posted: Tue  11 Sep 2007 07:52
				by Alexey
				There was no problem regarding this issue for regular MySQL servers.
The fix for embedded server is not released yet. Please wait a bit.
			 
			
					
				
				Posted: Fri  21 Sep 2007 14:45
				by Alexey
				Please try new build of MyDirect .NET available for download now!