Responder Developer Guide
DbConvert Class
Members 


Version: 10.2.1a

Resource Center Home

Product Availability
Responder
Required Licenses
Responder
.NET Assembly

Miner.Data.Access.dll

This non-creatable class contains helper methods for performing common conversions necessary when working with nullable values, such as working with database (DataRow) column values.
Object Model
DbConvert Class
Syntax
'Declaration
 
Public NotInheritable Class DbConvert 
'Usage
 
Dim instance As DbConvert
public sealed class DbConvert 
Remarks

When working with nullable types, such as any value stored in a object (i.e. a boxed value) you have to handle the situation where the value is null or DBNull. Often times it is much more convenient to convert a null value to some default; especially when the value will not be written back to the database.

The example below shows how to use the DbConvert helper methods. The code is cleaner and easier to understand than the later example that explicitly handles DBNull values.

public void DoSomethingIfStatusIsOne(DataRow row) { int status = DbConvert.ToInt32(row["status"], 0); if (status == 1) { DoSomething(); } } public void DoSomethingIfStatusIsOne(DataRow row) { object status = row["status"]; if ((status != DBNull.Value) && ((decimal)status == 1)) { DoSomething(); } } The status column is most likely a decimal value, not an integer because of the way Oracle and SqlServer store numbers in the database. Casting the status value to an int would lead to a runtime exception. The alternatives are to use Convert.ToInt32 or cast to int.
Inheritance Hierarchy

System.Object
   Miner.Data.Access.DbConvert

Requirements

Target Platforms: Windows XP SP3 (32-bit and 64-bit), Windows 7 (32-bit and 64-bit)

Not all Operating Systems are supported on all products. Visit the ArcFM Solution Supported Versions page for full details.

See Also

Reference

DbConvert Members
Miner.Data.Access Namespace
DbCompare Class

 

 


Send Comment