SqlDataReader.GetString and sqlnullvalueexception

前端 未结 4 1182
庸人自扰
庸人自扰 2020-12-03 13:38

I am new to C#. I was executing some select queries from database tables using System.Data.SqlClient classes. I got sqlnullvalueexception while executing some select query.

4条回答
  •  温柔的废话
    2020-12-03 14:22

    That really is the best way to go about it if you wish to avoid any exceptions. You need to decide whether or not a null field represents an exceptional situation in your code - if it doesn't then use this method. If it does then I would suggest that you either allow the exception to be thrown or catch the exception and wrap it in a more meaniful exception and throw that one.

    But the main thing to know is that this is the standard way to retrieve values from a data reader when a null field does not represent an exceptional situation in the application domain.

提交回复
热议问题