架构B/S四 DBUtility 数据层基类 放公共类(一) SqlHelper

放公共类

如:SQLHelper.cs数据访问抽象基础类    ControlBindHelper.cs 控件帮定抽象基础类 DataBase.cs 操作控件类 MessageBox.cs 显示消息提示对话框类。 PageValidate.cs 页面数据校验类  

SQLHelper.cs数据访问抽象基础类 代码

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using CoalTraffic.Common;

namespace CoalTraffic.DBUtility
{
    public class CommandInfo
    {
        public string CommandText;
        public SqlParameter[] Parameters;
    }
///


/// 数据访问抽象基础类
    /// Copyright (C) 2004-2008 By

///


public abstract class DbHelperSQL
{
        //数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库. 

        public static string connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
   public DbHelperSQL()
   {
        }

        #region 公用方法

        public static int GetMaxID(string FieldName,string TableName)
        {
            string strsql = "select max(" + FieldName + ")+1 from " + TableName;
            object obj = DbHelperSQL.GetSingle(strsql);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return int.Parse(obj.ToString());
            }
        }

        public static decimal GetMaxIDNum(string FieldName, string TableName)
        {
            string strsql = "select max(cast(" + FieldName + " as decimal(22)))+1 from " + TableName;
            object obj = DbHelperSQL.GetSingle(strsql);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return decimal.Parse(obj.ToString());
            }
        }

        ///


        /// 跟据当前ID,取得它的下一个ID
        ///

        /// 表名
        /// 主健名
        /// Where条件
        /// 当前ID
        /// 下一个ID
        public static string GetNextID(string strTableName,string strIDKey,string strWhere,string strCurrentID)
        {
            string strNextID = string.Empty;
            string strMinID = string.Empty;
            string strMaxID = string.Empty;
            if (strWhere == "")
            {
                string strSql = "Select Top 1 " + strIDKey + " From " + strTableName + " Order By " + strIDKey + " Asc";

                object objSaclar = DbHelperSQL.GetSingle(strSql);

                if (objSaclar != null && objSac

你可能感兴趣的:(string,object,null,exception,parameters,数据库)