when use IfxDataReader.GetIfxDateTime to NULL valu
Posted in 2013
A .NET developer got a "specified cast not valid" error when calling IfxDataReader.GetIfxDateTime() on a column containing NULL. The answer: test the column with IfxDataReader.IsDBNull() before calling any GetIfx* method; the poster confirmed this worked. Another contributor suggested alternatives such as reading the column via the indexer with C#'s null-coalescing operator or a null check. It was also noted that trimming a string can't be used to detect NULLs, since all-blank strings also trim to empty. The poster's server/CSDK versions (IDS 10.00.FC5, CSDK 2.90) were flagged as out of support.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: General Discussion
When use IfxDataReader.GetIfxDateTime method to read a NULL value field, it showed the error message "specified cast not valid" something like that. What should I do ? Use IfxDataReader["field name"].ToString() to check the length of the field before, and then, if = 0, set null value ?
Hello. You should be using an old CSDK version. Please post your Informix server version, and your CSDK version, in order we can help you. Information Center 12.10 shows these methods in class IfxDataReader: http://pic.dhe.ibm.com/infocenter/informix/v121/topic/com.ibm.netpr.doc/ids_net_ 083.htm Regards. Alexandre Marini IBM Informix Certified Professional v10 / v11.50 / v11.70 / v12.10 IBM Information Management Informix Technical Professional IBM Infosphere DataStage Technical Professional Informix Senior DBA - Orizon Brasil BRIUG website administrator Informix independent consultant > To: ids@iiug.org > From: chingsze@hkcts.com > Subject: when use IfxDataReader.GetIfxDateTime to NULL valu [31431] > Date: Tue, 17 Sep 2013 07:36:17 -0400 > > When use IfxDataReader.GetIfxDateTime method to read a NULL value field, it > showed the error message "specified cast not valid" something like that. > > What should I do ? > > Use IfxDataReader["field name"].ToString() to check the length of the field > before, and then, if = 0, set null value ? > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. >
You are supposed to use the IfxDataReader.IsDBNull method to detech whether the column value for the current row is NULL or not before calling the appropriate GetIfx* method for it! Art Art S. Kagel, Principal Consultant Advanced DataTools (www.advancedatatools.com) Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Advanced DataTools, the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Tue, Sep 17, 2013 at 7:36 AM, VINCENT YEUNG <chingsze@hkcts.com> wrote: > When use IfxDataReader.GetIfxDateTime method to read a NULL value field, it > showed the error message "specified cast not valid" something like that. > > What should I do ? > > Use IfxDataReader["field name"].ToString() to check the length of the field > before, and then, if = 0, set null value ? > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001a11c32e88acf60604e6935436
Art, Thanks. I use IfxDataReader.IsDBNull to detect the value of the specified field is NULL or not before getting the value. Your suggestion is workable. I have one thing to share with : when use the trim function to compress the string field, the string is empty.
True, but you can't use that to detect NULL strings because a string of spaces will also compress/trim down to am empty string. Art Art S. Kagel, Principal Consultant Advanced DataTools (www.advancedatatools.com) Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Advanced DataTools, the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Wed, Sep 18, 2013 at 5:08 AM, VINCENT YEUNG <chingsze@hkcts.com> wrote: > Art, > > Thanks. > > I use IfxDataReader.IsDBNull to detect the value of the specified field is > NULL or not before getting the value. > > Your suggestion is workable. > > I have one thing to share with : when use the trim function to compress the > string field, the string is empty. > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001a11c3f400e2529304e6a7648a
You can use the null coalescing operator ( ??) ... public OdbcDataReader dr; // or ifxdatareader (.. read some stuff) string dte = (dr["somedatecol"] ?? "").ToString() ; if (dte.Length > 0) { some code; } OR ... string dte = dr["somedatecol"] ; if ( dte != is null ) { some code; } -----Original Message----- From: Art Kagel Sent: Tuesday, September 17, 2013 7:19 AM To: ids@iiug.org Subject: Re: when use IfxDataReader.GetIfxDateTime to N.... [31433] You are supposed to use the IfxDataReader.IsDBNull method to detech whether the column value for the current row is NULL or not before calling the appropriate GetIfx* method for it! Art Art S. Kagel, Principal Consultant Advanced DataTools (www.advancedatatools.com) Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Advanced DataTools, the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Tue, Sep 17, 2013 at 7:36 AM, VINCENT YEUNG <chingsze@hkcts.com> wrote: > When use IfxDataReader.GetIfxDateTime method to read a NULL value field, > it > showed the error message "specified cast not valid" something like that. > > What should I do ? > > Use IfxDataReader["field name"].ToString() to check the length of the > field > before, and then, if = 0, set null value ? > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001a11c32e88acf60604e6935436 ******************************************************************************* Forum Note: Use "Reply" to post a response in the discussion forum.
Hello, The version of Informix products in my environment is: Database server: AIX IBM Informix Dynamic Server Version 10.00.FC5 IBM Informix CSDK Version 2.90 IBM-ESQL Version 2.90.FC4 Client: PC Windows IBM Informix-ESQL 3.70.TC5DE.
You ar aware that your server and CSDK versions on AIX are out-of-support. You should consider upgrading. Art Art S. Kagel, Principal Consultant Advanced DataTools (www.advancedatatools.com) Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Advanced DataTools, the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Thu, Sep 19, 2013 at 2:53 AM, VINCENT YEUNG <chingsze@hkcts.com> wrote: > Hello, > > The version of Informix products in my environment is: > > Database server: AIX > IBM Informix Dynamic Server Version 10.00.FC5 > IBM Informix CSDK Version 2.90 IBM-ESQL Version 2.90.FC4 > > Client: PC Windows > IBM Informix-ESQL 3.70.TC5DE. > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --089e0141a16e9dbb8c04e6ee148c