More In-Depth About Nulls And DBNull
page 5 of 7
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 42074/ 91

Table Adapters

Table adapters generate their own interface based on the methods you create.  For instance, if a table that has the fields ID, Name, and Text, and the adapter generates the insert, update, and delete SQL statements, the adapter will create overloaded Insert, Update, and Delete methods with these fields as the parameters.  However, you will notice that it will use nullable type values for the value type parameters.

It may seem that a nullable type will be equivalent to DBNull, but the table adapter transforms a nullable type to DBNull, when the final execution is performed.  The adapter has its own interface for doing so.  However, when using a table adapter to return a custom data table and rows, there are special methods for determining if a field is null, and for setting it to null.  These methods are in the construct of Is<ColumnName>Null and Set<ColumnName>Null.  This handles using null values for particular fields.


View Entire Article

User Comments

Title: Nasty syntax for getting round this   
Name: Tyrannosaurs
Date: 2008-02-20 11:50:11 AM
Comment:
You cast a null date time to a dbnull like this:

datetime? myDateTime;

myDateTime = null;

.... parameters.add(...).value = (object)myDateTime ?? System.DBNull.Value;

It's pretty horrible but works and is no worse than most of the alternatives.
Title: DBNULL   
Name: g
Date: 2007-11-19 6:37:19 AM
Comment:
this concept can be dealt in more detail
Title: Datetime & DBNull Reply   
Name: Brian
Date: 2007-11-10 11:29:55 PM
Comment:
You can't cast directly; DBNULL and DateTIme are two separate object types, and you can't cast one to the other. However, in an ADO.NET datarow object, the underlying value is object, which could accept both. However, if the field is not null, then you can't assign a null value to it. It all depends on your code.
Title: Datetime&DBnull   
Name: Erick
Date: 2007-11-09 6:49:21 AM
Comment:
When I assigned DBNull.Value to System.Datetime, it raised a exception. Can I set a Datetime field of the database to null by using DBNull.Value in ADO.net?






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-06-19 7:53:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search