DataTable IsNull() Returns True on zero length strings
DataTable IsNull() Returns True on zero length strings
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.
Thanks for the help.
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.
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.
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.