1. 程式人生 > >C# http服務端介面,通用資料庫介面、與普通字串型別介面

C# http服務端介面,通用資料庫介面、與普通字串型別介面

1、通用資料庫介面,返回型別為dt

2、字串型別介面,傳入關鍵字引數,返回型別為字串

    [ServiceContract]
    public interface IDataBaseService
    {

        #region 通用資料庫訪問介面

        [OperationContract]
        DataTable ExecuteDataTable(string strSQL);

        [OperationContract]
        int ExecuteNonQuery(string strSQL);

        [OperationContract]
        bool ExecuteNonQueryEx(string[] strSQL);

        [OperationContract]
        object ExecuteScalar(string strSQL);
      
        [OperationContract]
        DataTable DataProcess(string strSQL);

        [OperationContract]
        string DataProcessEx(string command);
        #endregion
        
    }

介面的實現類:

   public class DataService : IDataBaseService
    {
        #region 資料庫訪問通用介面

        public DataTable ExecuteDataTable(string strSQL)
        {
            DataTable dt = new DataTable();
            try
            {
                DbHelper helper = new DbHelper();
                
                dt = helper.ExecuteDataTable(strSQL);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public int ExecuteNonQuery(string strSQL)
        {
            try
            {
                DbHelper helper = new DbHelper();
                return helper.ExecuteNonQuery(strSQL);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool ExecuteNonQueryEx(string []strSQL)
        {
            try
            {
                DbHelper helper = new DbHelper();
                return helper.ExecuteNonQuery(strSQL);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public object ExecuteScalar(string strSQL)
        { 
            try
            {
                DbHelper helper = new DbHelper();
                return helper.ExecuteScalar(strSQL);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable DataProcess(string strSQL)
        {
            try
            {
                return DBService.DataProcess(strSQL);
            }
            catch (Exception ex)
            {
                return null;
                //throw ex;
            }
        }
        public string DataProcessEx(string command)
        {
            try
            {
                return DBService.DataProcessEx(command);
            }
            catch (Exception ex)
            {
                return null;
                //throw ex;
            }
        }
        #endregion


    }