久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

連接數(shù)據(jù)庫(kù)

 shymi 2010-09-20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Windows.Forms;
namespace WindowsFormsApplication1.ItemClass
{
    public class SqlBaseClass
    {
        #region 代碼中用到的變量
        SqlDataAdapter adp;
        DataSet ds;
        SqlCommand cmd;
        SqlDataReader dr;
        string connectionString = "server=.;database=db_GoodsManageData;User ID=sa;Pwd=aa";
        SqlConnection conn;
        #endregion
        #region 鏈接數(shù)據(jù)庫(kù)
        /// <summary>
        /// 鏈接數(shù)據(jù)庫(kù)
        /// </summary>
        /// <returns></returns>
        public SqlConnection GetCon()
        {
            conn = new SqlConnection(connectionString);
            conn.Open();   //打開(kāi)鏈接
            return conn;   //返回鏈接字符串
        }
        #endregion
        #region 執(zhí)行SQL語(yǔ)句
        /// <summary>
        /// 執(zhí)行SQL語(yǔ)句
        /// </summary>
        /// <param name="cmdText">要執(zhí)行的SQL語(yǔ)句</param>
        /// <returns></returns>
        public bool GetExecute(string cmdText)
        {
            cmd = new SqlCommand(cmdText,GetCon());
            try
            {
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("錯(cuò)誤:" + ex.Message, "錯(cuò)誤提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return false;
            }
            finally
            {
                if (GetCon().State == ConnectionState.Open)
                {
                    //如果數(shù)據(jù)庫(kù)鏈接處于打開(kāi)狀態(tài),,則關(guān)閉連接并釋放占用的資源
                    GetCon().Close();
                    GetCon().Dispose();
                }
            }
        }
        #endregion
        #region 返回?cái)?shù)據(jù)集
        /// <summary>
        /// 返回?cái)?shù)據(jù)集類型
        /// </summary>
        /// <param name="cmdText">要執(zhí)行的SQL語(yǔ)句</param>
        /// <returns></returns>
        public DataSet  GetDs(string cmdText)
        {
            try
            {
                adp = new SqlDataAdapter(cmdText,GetCon());
                ds = new DataSet();
                adp.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                MessageBox.Show("錯(cuò)誤:" + ex.Message, "錯(cuò)誤提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return null;
            }
            finally
            {
                if (GetCon().State == ConnectionState.Open)
                {
                    //如果數(shù)據(jù)庫(kù)鏈接處于打開(kāi)狀態(tài),,則關(guān)閉連接并釋放占用的資源
                    GetCon().Close();
                    GetCon().Dispose();
                }
            }
        }
        #endregion
        #region 返回SqlDataReader類型數(shù)據(jù)
        /// <summary>
        /// 返回SqlDataReader類型數(shù)據(jù)
        /// </summary>
        /// <param name="cmdText">要執(zhí)行的SQL語(yǔ)句</param>
        /// <returns></returns>
        public SqlDataReader  GetReader(string cmdText)
        {
            cmd = new SqlCommand(cmdText ,GetCon());
            try
            {
                dr = cmd.ExecuteReader();
                return dr;
            }
            catch (Exception ex)
            {
                MessageBox.Show("錯(cuò)誤:" + ex.Message, "錯(cuò)誤提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return null ;
            }
            finally
            {
                if (GetCon().State == ConnectionState.Open)
                {
                    //如果數(shù)據(jù)庫(kù)鏈接處于打開(kāi)狀態(tài),,則關(guān)閉連接并釋放占用的資源
                    GetCon().Close();
                    GetCon().Dispose();
                }
            }
        }
        #endregion
    }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多