Questions tagged [dbnull]

DBNull is a special value in The .Net framework indicating that the value is NULL in the database.

DBNull is a special value in the .Net framework indicating that the value is NULL in the database. It is required to disambiguate with .Net null, which basically means 'null pointer' or unallocated variable. Since it is a special value, it requires special handling to convert into other data types, check DB data for null values etc.

.Net uses System.DBNull singleton class to handle database values.

The DBNull class represents a nonexistent value. In a database, for example, a column in a row of a table might not contain any data whatsoever. That is, the column is considered to not exist at all instead of merely not having a value. A DBNull object represents the nonexistent column. Additionally, COM interop uses the DBNull class to distinguish between a VT_NULL variant, which indicates a nonexistent value, and a VT_EMPTY variant, which indicates an unspecified value.

In a relational database, null is used to describe a missing/unknown value, not to be confused with null (Nothing in ) - that's a reference that points nowhere.

322 questions
2
votes
4 answers

Why can't I insert DBNull.Value into a nullable image-field in sql server 2005?

Why can't I insert DBNull.Value into a nullable image-field in sql server 2005? I tried this code: SqlConnection conn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=PrescriptionTrackingSystem;Integrated Security=True"); …
user366312
  • 16,949
  • 65
  • 235
  • 452
2
votes
3 answers

VB.NET: How do I use coalesce with db column values and nullable types? Or is there a better solution?

I'm trying to do something similar to what's described here, but with nullable types. http://www.csharp-station.com/Tutorials/Lesson23.aspx int availableUnits = unitsInStock ?? 0; In VB, it would be this: Dim availableUnits As Int32 =…
ingredient_15939
  • 3,022
  • 7
  • 35
  • 55
2
votes
4 answers

What Is DBNull Needed For Anyway?

Possible Duplicate: What is the point of DBNull? Since the beginning of my adventure with .NET I have always asked myself one question: why do we need the DBNull type? Is a simple null reference not enough? MSDN says that DBNull "Represents a…
Pankaj Agarwal
  • 11,191
  • 12
  • 43
  • 59
2
votes
1 answer

Informix (C#): How do I properly set/unset a blob field?

IBM Informix SDK: Statement: Update mytable set myblobcolumn = ? where myid = 1; using (IfxConnection conn = GetIfxConnection()) using (IfxCommand cmd = new IfxCommand(updateSql, conn)) { var param = new IfxParameter("myblobcolumn",…
myermian
  • 31,823
  • 24
  • 123
  • 215
2
votes
4 answers

DBNull to String in ASP.NET inline expressions has casting error

Hey guys, a table in my database has a field "Description" that Allow's Nulls'. This causes a problem when rendering the page in ASP.NET since I want to make sure I'm decoding the string as its coming out of the database as I'm encoding it on the…
Tomasz Iniewicz
  • 4,379
  • 6
  • 42
  • 47
2
votes
5 answers

Dataset field DBNull -> int?

SQLServer int field. Value sometimes null. DataAdapter fills dataset OK and can display data in DatagridView OK. When trying to retrieve the data programmatically from the dataset the Dataset field retrieval code throws a StronglyTypedException…
BobClegg
2
votes
2 answers

why dataTable.Rows[0]["columnName"] == null. not working?

I have a code like below txtbox1.Text = dtDetails.Rows[0]["columnName"] == null ? "--": dtDetails.Rows[0]["columnName"].ToString().Trim(); above line is always not null even though dtDetails.Rows[0]["columnName"] is null whereas txtbox1.Text =…
Hussain Md
  • 119
  • 1
  • 11
2
votes
3 answers

Object cannot be assigned to other types from DBNull

I get minimum number in my database. But when no data in my database I get this error. System.InvalidCastException: 'The object cannot be assigned to other types from DBNull.' Code: SqlCommand cmd = new SqlCommand("SELECT MAX(GidenEvrakSira)…
kozyalcin
  • 83
  • 10
2
votes
1 answer

How performant is the DBNull.Value.Equals() check?

I know it's probably not enough to be worried about, but how performant is the DBNull.Value.Equals() check? public IEnumerable Query(string sql, params object[] args) { using (var conn = OpenConnection()) { var rdr =…
Chaddeus
  • 13,134
  • 29
  • 104
  • 162
2
votes
3 answers

Updating column with Null value

I have a date field (smalldatetime) in a table and in particular cases I need to set the date field to null. Currently, when setting the sqlparameter.value property to a date endDateParam.Value = "5/15/2011" the field is updated with the proper…
user356808
2
votes
1 answer

How to generate IS NULL and IS NOT NULL in Entity Framework 6 in LEFT JOIN

This is the scenario. I have two tables in a 1-to-M relation; For illustration purposes lets define them as MyHeaderTable (headerID, col1, col2) MyDetailTable (lineID, headerID, statusID, col3, col4) Note the child rows are optional (header record…
joedotnot
  • 4,810
  • 8
  • 59
  • 91
2
votes
2 answers

How do I handle a DBNull to Boolean conversion in my XSD DataSet?

In my database, I have a few columns in one of my tables that are bit (boolean) values. They are allowed to be NULL since the fields are not always going to contain data. I've gone through the process of creating an XSD DataSet using the table and…
Dillie-O
  • 29,277
  • 14
  • 101
  • 140
2
votes
2 answers

how to set DBnull value for char

I am working on application in that fetching record from database.but when fetching char datatype of value is null then it shows error. here is my Code: SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { …
Anuja
  • 97
  • 1
  • 1
  • 11
2
votes
1 answer

Cannot compare DbGeometry with null value to DbNull even when exception throw DbNull as type

As in title, I have a code, where I recieve DbNull type with null value, when there is no geometry in database and DbGeometry get null value. But when I want to make an if statement to check if DbGeometry equals to DbNull.Value I can't do that. It's…
MichalT
  • 91
  • 4
2
votes
5 answers

How to create a condition to check if the datatable item is null in vb

Now I want if the dt.rows(i).item(0) is null, then some code.. This is my code: If dtpay.Rows(i).Item(23).ToString Is Nothing Then GoTo finalline End If But seems like the code is not working.. Thanks a lot for your concern :D
Johns Yong
  • 57
  • 1
  • 2
  • 7