c# - How to omit checking for SqlNullValueException in Mysql Connector/NET -


when reading data reader have check each parameter allows null values in database whether threw nullvalueexception. have check each value separate try/catch because still want parse next value first 1 null. in c# classes have tryparse(key, out value) function, returns boolean on success, didn't find connector/net. there way shorten following statements?

product product; try {     product = new product(         reader.getstring("product_id"),         reader.getdatetime("starttime")         );     try {         product.endtime = reader.getdatetime("endtime");     } catch (system.data.sqltypes.sqlnullvalueexception) { }     try {         product.description = reader.getstring("description");     } catch (system.data.sqltypes.sqlnullvalueexception) { }     try {         product.type = reader.getstring("type");     } catch (system.data.sqltypes.sqlnullvalueexception) { } } catch (mysqlexception ex) {     throw ex; } catch (exception ex) {     throw ex; } 

i use pattern sqldatareader, imagine should same mysql connector/net.

product.endtime = reader["endtime"] datetime? ?? datetime.minvalue; product.description = reader["description"] string; product.type = reader["type"] string; 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -