dbnull

Crystal report not support null Datetime

喜你入骨 提交于 2019-12-20 05:13:35
问题 I am using crystal report with ado.Net, when datetime is coming null from database then showing error. if we use Nullable (using ?) property then crystal report can't support. Like:- _report = ( from user in users select new userModel() { UserId = user.Field<string>("userid"), CheckInTime = <user.Field<DateTime>("intime"), CheckOutTime = user.Field<DateTime>("outime"), TotalWorks = user.Field<Int32>("TotalWork") }) .ToList(); throwing error here...... and when we use Nullabe..:- public

Parsing a DBNULL value into double

随声附和 提交于 2019-12-20 05:13:06
问题 I use the following line to convert the datarow value into double. double.parse(Convert.ToString(datarow)); If the datarow is DBNULL , I am getting the following exception: 'double.Parse(Convert.ToString(data))' threw an exception of type 'System.FormatException' How to handle this one without using tryparse. 回答1: Another alternative would be to check if the datarow is DBNull : double d = datarow is DBNull ? 0 : double.Parse(Convert.ToString(datarow)); This way, you do not need to check for

Parsing a DBNULL value into double

大憨熊 提交于 2019-12-20 05:12:10
问题 I use the following line to convert the datarow value into double. double.parse(Convert.ToString(datarow)); If the datarow is DBNULL , I am getting the following exception: 'double.Parse(Convert.ToString(data))' threw an exception of type 'System.FormatException' How to handle this one without using tryparse. 回答1: Another alternative would be to check if the datarow is DBNull : double d = datarow is DBNull ? 0 : double.Parse(Convert.ToString(datarow)); This way, you do not need to check for

Conversion from type 'DBNull' to type 'String' is not valid

我的梦境 提交于 2019-12-18 03:05:46
问题 i am receiving this problem Conversion from type 'DBNull' to type 'String' is not valid. Line 501: hfSupEmail.Value = dt.Rows(0)("SupEmail") i am very new to this, i am not really sure what is the exact problem could someone guide me? Many thanks 回答1: The quick and dirty fix: hfSupEmail.Value = dt.Rows(0)("SupEmail").ToString() This works very well when your eventual target and the source data are already strings. This is because any extra .ToString() call for something that's already a

SQLite equivalent to ISNULL(), NVL(), IFNULL() or COALESCE()

最后都变了- 提交于 2019-12-17 07:15:33
问题 I'd like to avoid having many checks like the following in my code: myObj.someStringField = rdr.IsDBNull(someOrdinal) ? string.Empty : rdr.GetString(someOrdinal); I figured I could just have my query take care of the nulls by doing something like this: SELECT myField1, [isnull](myField1, '') FROM myTable1 WHERE myField1 = someCondition I'm using SQLite though and it doesn't seem to recognize the isnull function. I've also tried some equivalent ones recognized in other databases ( NVL() ,

Handle DBNull in C#

牧云@^-^@ 提交于 2019-12-17 07:14:51
问题 Is there a better/cleaner way to do this? int stockvalue = 0; if (!Convert.IsDBNull(reader["StockValue"])) stockvalue = (int)reader["StockValue"]; 回答1: The shortest (IMHO) is: int stockvalue = (reader["StockValue"] as int?) ?? 0; Explanation: If reader["StockValue"] is of type int , the value will be returned, and the "??" operator will return the result If reader["StockValue"] is NOT of type int (e.g. DBNull), null will be returned, and the "??" operator will return the value 0 (zero). 回答2:

Why is this code invalid in C#?

别来无恙 提交于 2019-12-17 06:06:35
问题 The following code will not compile: string foo = "bar"; Object o = foo == null ? DBNull.Value : foo; I get: Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'string' To fix this, I must do something like this: string foo = "bar"; Object o = foo == null ? DBNull.Value : (Object)foo; This cast seems pointless as this is certainly legal: string foo = "bar"; Object o = foo == null ? "gork" : foo; It seems to me that

handling dbnull data in vb.net

自古美人都是妖i 提交于 2019-12-17 04:30:28
问题 I want to generate some formatted output of data retrieved from an MS-Access database and stored in a DataTable object/variable, myDataTable. However, some of the fields in myDataTable cotain dbNull data. So, the following VB.net code snippet will give errors if the value of any of the fields lastname , intials , or sID is dbNull . dim myDataTable as DataTable dim tmpStr as String dim sID as Integer = 1 ... myDataTable = myTableAdapter.GetData() ' Reads the data from MS-Access table ... For

.NET DBNull vs Nothing across all variable types?

戏子无情 提交于 2019-12-14 00:51:41
问题 I am a little confused about null values and variables in .NET. (VB preferred) Is there any way to check the "nullness" of ANY given variable regardless of whether it was an object or a value type? Or does my null check have to always anticipate whether it's checking a value type (e.g. System.Integer) or an object? I guess what I'm looking for is a function that checks all possible kind of null-ness. That is, any type of variables that a) were never assigned a value since declared b) were

using datareader with dbnull values in .net4

浪尽此生 提交于 2019-12-13 15:06:32
问题 I heard there is a field extension method in framework 4 that permits one to receive null values from a datareader, without having to go through the process of first testing if not null then ... etc. There's information about the extension method here (MSDN), but i don't know how to use it in code (am relatively new to .net and never used extension methods before). Would appreciate if anyone can give an example. This is what i tried to implement, but it returns an error when a dbnull is