Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
GetSafeData.cs
Package: moban.rar [view]
Upload User: szraylite
Upload Date: 2018-06-06
Package Size: 11546k
Code Size: 2k
Category:
Software Testing
Development Platform:
Java
- using System;
- using System.Data;
- namespace ENTERPRISE.DataAccessHelper
- {
- /// <summary>
- /// 从数据库中安全获取数据,即当数据库中的数据为NULL时,保证读取不发生异常。
- /// </summary>
- public class GetSafeData
- {
- #region DataRow
- /// <summary>
- /// 从一个DataRow中,安全得到列colname中的值:值为字符串类型
- /// </summary>
- /// <param name="row">数据行对象</param>
- /// <param name="colname">列名</param>
- /// <returns>如果值存在,返回;否则,返回System.String.Empty</returns>
- public static string ValidateDataRow_S(DataRow row,string colname)
- {
- if(row[colname]!=DBNull.Value)
- return row[colname].ToString();
- else
- return System.String.Empty;
- }
- /// <summary>
- /// 从一个DataRow中,安全得到列colname中的值:值为整数类型
- /// </summary>
- /// <param name="row">数据行对象</param>
- /// <param name="colname">列名</param>
- /// <returns>如果值存在,返回;否则,返回System.Int32.MinValue</returns>
- public static int ValidateDataRow_N(DataRow row,string colname)
- {
- if(row[colname]!=DBNull.Value)
- return Convert.ToInt32(row[colname]);
- else
- return System.Int32.MinValue;
- }
- /// <summary>
- /// 从一个DataRow中,安全得到列colname中的值:值为浮点数类型
- /// </summary>
- /// <param name="row">数据行对象</param>
- /// <param name="colname">列名</param>
- /// <returns>如果值存在,返回;否则,返回System.Double.MinValue</returns>
- public static double ValidateDataRow_F(DataRow row,string colname)
- {
- if(row[colname]!=DBNull.Value)
- return Convert.ToDouble(row[colname]);
- else
- return System.Double.MinValue;
- }
- /// <summary>
- /// 从一个DataRow中,安全得到列colname中的值:值为时间类型
- /// </summary>
- /// <param name="row">数据行对象</param>
- /// <param name="colname">列名</param>
- /// <returns>如果值存在,返回;否则,返回System.DateTime.MinValue;</returns>
- public static DateTime ValidateDataRow_T(DataRow row,string colname)
- {
- if(row[colname]!=DBNull.Value)
- return Convert.ToDateTime(row[colname]);
- else
- return System.DateTime.MinValue;
- }
- #endregion DataRow
- }
- }