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
0
votes
1 answer

Real difference between DBNull.Value and just null?

In essence my question is really about DBNull.Value. What is it compared to just null? It seems you cannot simply pass a 'null' to a command parameter unless it's a DBNull.Value, otherwise the database will reject it, but why?
LoftyWofty
  • 87
  • 1
  • 8
0
votes
2 answers

Object cannot be cast from DBNull to other types in linq expression

var gFieldList = new List() { "Supplier", "Country" }; var sFieldList = new List() { "Sales"}; var gField = string.Join(", ", gFieldList.Select(x => "it[\"" + x + "\"] as " + x)); var sField = string.Join(", ",…
0
votes
1 answer

How to handle the DBNull with Expression in this case?

I have use the following code snippet to some Comparison Expression.Constant(DBNull.Value, typeof (Int32)); While execute these lines I got the following Exception System.ArgumentException occurred HResult=-2147024809 Message=Argument types do not…
Uthistran Selvaraj.
  • 558
  • 2
  • 11
  • 29
0
votes
0 answers

Null Reference in datagridview with "Not IsDBNull"

IN VB.net 2012 this is my code: For Each row As DataGridViewRow In DataGridViewAddPlanning.Rows If Not IsDBNull(row.Cells(0).Value) Then Dim sqlcmd As SqlClient.SqlCommand = New SqlClient.SqlCommand() …
Simeon
  • 74
  • 6
0
votes
3 answers

DBnull in Linq query causing problems

i am doing a query thus: int numberInInterval = (from dsStatistics.J2RespondentRow item in jStats.J2Respondent where item.EndTime > dtIntervalLower && item.EndTime <= dtIntervalUpper select item).count(); there…
nat
  • 9
  • 2
0
votes
2 answers

'DBNull' Error when attempting to set a range in VB.net. Database is Excel

I've written a pretty useful macro within Excel in VBA and am attempting to transfer it to a stand-alone windows application written in VB.net. I've found all the referencing pretty confusing and am now facing trouble in converting the general…
Josh
  • 27
  • 1
  • 1
  • 8
0
votes
1 answer

How can i get the SCOPE_IDENTITY() From SP?

Im trying to get the SCOPE_IDENTITY to my vb.NET App from a Stored Procedure But i get DBNull Exception. This is my SP: ALTER PROCEDURE [dbo].[sp_XYZ] @ID INT, @OtherID INT OUTPUT AS BEGIN SELECT @Name = name, FROM dbo.PERSON WHERE id =…
0
votes
3 answers

cmd.Parameters.AddWithValue("@param1",param1 ?? DbNull.Value)

I have int? type value which can be either null or have some value. I want to execute a insert statement using parametrized query to insert accordingly. int? val1=null; SqlCeCommand cmd; string insert = "insert into table(col1)values(@col_1)"; cmd…
Arti
  • 2,993
  • 11
  • 68
  • 121
0
votes
1 answer

null / DBNull conversion

i have a method void addParam(string name, object value); and an object public class Foo { public string Whatever; } what is the best way to perform a (working) call that would match this logic? addParam("foo", Foo.Whatever == null ?…
user887983
0
votes
2 answers

Using DBNullable Types

Here's the code: protected void btnSearch_Click(object sender, EventArgs e) { List completelist = new List(); DALbatter batter = new DALbatter(); batter.NameLast = txtLastName.Text; DataTable batters =…
dwarf
  • 445
  • 2
  • 9
  • 23
0
votes
2 answers

How do I get a value from a database using Oledb, I keep getting a DBNull exception?

int weaponDamage = Convert.ToInt32(dt.Rows[randomItem][2]); // dt= DataTable // randomItem = randomly chooses a row from the datatable That code throws "InvalidCastException was unhandled, Object cannot be cast from DBNull to other types". Yes…
Frapie
  • 225
  • 1
  • 6
  • 14
0
votes
1 answer

Gridview null values for datetime in database results Object Can Not be cast from DBNULL to other types error

I am using the gridview control which is connected to my database with an sqldatasource. I can do updates and deletes directly from this gridview. When I edit a date field and remove the content, instead of writing null to database, it changes the…
HOY
  • 1,067
  • 10
  • 42
  • 85
0
votes
2 answers

Handle an object that has error and is not compareable to null or DBnull.value

I have a Class (Entity we call them) Named Person which is mapped to a database Table (Person table). The records of this table may contain null values in all fields but one, the PK. This is in brief how we define our Person entity: ... private…
Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
0
votes
1 answer

How to handle nulls in a repeater?

My page is have issues because some columns values in a row are NULL, how can I only display the value if it is NOT NULL? <%# Eval("some_db_column") %> …
loyalflow
  • 14,275
  • 27
  • 107
  • 168
0
votes
1 answer

LINQ CopyToDataTable -- Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type

I am parsing two Excel files that contain many fields, most importantly TOTAL_DOLLARS and TOTAL_UNITS fields, that often have values, but some of them are left blank, or null. I want to JOIN these two DataTables using LINQ where the UPC fields are…
user1077685