`

C# SQLServer 数据库连接类

阅读更多

using System;
using System.Data;
using System.Configuration;
using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
//using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.Collections;
namespace domain.SQLDB
{

    public class DbAccess
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public DbAccess()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
            conn = new SqlConnection();
            conn.ConnectionString =  Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["datasource"]);
            //conn.ConnectionString = "initial catalog=idyan_new;data source=.;user id=bt;password=btbtbtbt;Connect Timeout=5000";
            cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandTimeout = 0;
    
        }
        public DbAccess(string constr)
        {
         
            //
            // TODO: 在此处添加构造函数逻辑
            //
            conn = new SqlConnection();
            conn.ConnectionString = constr;// "initial catalog=idyan_new;data source=.;user id=bt;password=btbtbtbt";
            cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandTimeout = 0;
         
        }
        /// <summary>
        /// 获取数据根据sql语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataTable GetTable(string sql)
        {
            DataSet ds = new DataSet();
            try
            {
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;

            }
            return ds.Tables[0] ?? new DataTable();
        }
        /// <summary>
        /// 获取数据根据sql语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataSet GetDataSet(string sql)
        {
            DataSet ds = new DataSet();

            try
            {
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;

            }
            return ds;
        }
        /// <summary>
        /// 获取数据根据sql语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataSet GetDataSet(string sql,SqlParameter[] pas)
        {
            DataSet ds = new DataSet();

            try
            {
                cmd.Parameters.Clear();
                cmd.CommandText = sql;
                foreach (SqlParameter pa in pas)
                {
                    cmd.Parameters.Add(pa);
                }
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;

            }
            return ds;
        }
        /// <summary>
        /// 获取数据根据sql语句 带参数 的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public DataTable GetTable(string sql, params SqlParameter[] pas)
        {
            DataSet ds = new DataSet();
            try
            {
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                cmd.Parameters.Clear();

                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }


                da.Fill(ds);
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return ds.Tables[0] ?? new DataTable();
        }
        /// <summary>
        /// 获取数据根据sql语句 带参数 的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public DataTable GetProcTable(string procname, params SqlParameter[] pas)
        {
            DataSet ds = new DataSet();
            try
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = procname;
                //cmd.CommandText = sql;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                cmd.Parameters.Clear();

                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }
              


                da.Fill(ds);
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return ds.Tables[0] ?? new DataTable();
        }
        /// <summary>
        /// 获取数据根据sql语句 带参数 的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public DataTable GetProcCursorTable(string procname, params SqlParameter[] pas)
        {
            DataSet ds = new DataSet();
            try
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = procname;
                //cmd.CommandText = sql;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                cmd.Parameters.Clear();

                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }

 

                da.Fill(ds);
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return ds.Tables[1] ?? new DataTable();
        }
        /// <summary>
        /// 获取数据根据sql语句 带参数 的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public int  GetProcState(string procname, params SqlParameter[] pas)
        {
            int state = 0;
            try
            {
                OpenConn();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = procname;
                cmd.Parameters.Clear();
                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }
                cmd.ExecuteNonQuery();
                CloseConn();
                state = Convert.ToInt32(pas[pas.Length - 1].Value);
             
            }
            catch
            {
                return 0;
            }
            return state;
        }
        /// <summary>
        /// 获取数据根据sql语句 带参数 的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public int GetProcStateNo(string procname, params SqlParameter[] pas)
        {
            int state = 0;
            try
            {
                OpenConn();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = procname;
                cmd.Parameters.Clear();
                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }
                cmd.ExecuteNonQuery();
                CloseConn();
                state = 1;
               // state = Convert.ToInt32(pas[pas.Length - 1].Value);

            }
            catch(Exception ex)
            {

                return 0;
            }
            return state;
        }
        /// <summary>
        /// 根据sql语句返回跟新状态
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public bool GetState(string sql)
        {
            bool succ = false;
            try
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                OpenConn();
                succ = cmd.ExecuteNonQuery() > 0 ? (true) : (false);
                CloseConn();
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return false;
            }
            return succ;

        }
        /// <summary>
        /// 根据sql语句返回跟新状态带参数的
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="pas">参数的集合</param>
        /// <returns></returns>
        public bool GetState(string sql, params SqlParameter[] pas)
        {
            bool succ = false;
            try
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                cmd.Parameters.Clear();

                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }
                OpenConn();
                succ = cmd.ExecuteNonQuery() > 0 ? (true) : (false);
                CloseConn();
            }
            catch (Exception ex)
            {

               // this.ShowError(ex.Message);
                //using (System.IO.StreamWriter sw = new System.IO.StreamWriter("D:\\error2008.txt"))
                //{
                //    sw.Write(ex.Message);
                //    sw.Flush();
                //}
                return false;
            }
            return succ;

        }
        /// <summary>
        /// 根据sql语句返回第一个单元格的数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public string GetOne(string sql)
        {
            string res = "";
            try
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                OpenConn();
                res = cmd.ExecuteScalar() == null ? ("") : (Convert.ToString(cmd.ExecuteScalar()));
                CloseConn();
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return res;
        }
        /// <summary>
        ///  根据sql语句返回第一个单元格的数据带参数的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public string GetOne(string sql, params SqlParameter[] pas)
        {
            string res = "";
            try
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                cmd.Parameters.Clear();

                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }
                OpenConn();
                res = cmd.ExecuteScalar() == null ? ("") : (Convert.ToString(cmd.ExecuteScalar()));
                CloseConn();
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return res;
        }
        /// <summary>
        /// 返回数据的DataReader
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public SqlDataReader GetDataReader(string sql)
        {
            SqlDataReader dr = null;
            try
            {
                cmd.CommandType = CommandType.Text;
                conn.Open();
                cmd.CommandText = sql;
                dr = cmd.ExecuteReader();
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return dr;
        }
        /// <summary>
        /// 返回数据的DataReader带参数的
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pas"></param>
        /// <returns></returns>
        public SqlDataReader GetDataReader(string sql, params SqlParameter[] pas)
        {
            SqlDataReader dr = null;
            try
            {
                cmd.CommandType = CommandType.Text;
                conn.Open();
                cmd.Parameters.Clear();

                foreach (SqlParameter temppa in pas)
                {
                    cmd.Parameters.Add(temppa);
                }

                cmd.CommandText = sql;
                dr = cmd.ExecuteReader();
            }
            catch (Exception ex)
            {

                this.ShowError(ex.Message);
                return null;
            }
            return dr;
        }
        /// <summary>
        /// 事务处理函数
        /// </summary>
        /// <param name="al"></param>
        /// <returns></returns>
        public bool GetTranState(ArrayList al)
        {
            cmd.CommandType = CommandType.Text;
            OpenConn();
            SqlTransaction tran = conn.BeginTransaction();
            cmd.Transaction = tran;
            try
            {
                for (int i = 0; i < al.Count; i++)
                {
                    cmd.CommandText = Convert.ToString(al[i]);
                    cmd.ExecuteNonQuery();
                }
           
                tran.Commit();  
                CloseConn();
            }
            catch (Exception ex)
            {

                tran.Rollback();
                return false;
            }
            return true;

        }
        /// <summary>
        /// 事务处理函数
        /// </summary>
        /// <param name="al"></param>
        /// <returns></returns>
        public bool GetTranStateParameter(ArrayList al)
        {
            cmd.CommandType = CommandType.Text;
            OpenConn();
            SqlTransaction tran = conn.BeginTransaction();
            cmd.Transaction = tran;
            try
            {
                for (int i = 0; i < al.Count; i++)
                {
                    SqlTranModel stm = (SqlTranModel)al[i];
                    cmd.CommandText = Convert.ToString(stm.Sql);
                    SqlParameter[] pas = stm.Pas;
                    cmd.Parameters.Clear();
                    foreach (SqlParameter temp in pas)
                    {
                        cmd.Parameters.Add(temp);
                    }
                    cmd.ExecuteNonQuery();
                }

                tran.Commit();
                CloseConn();
            }
            catch (Exception ex)
            {

                tran.Rollback();
                return false;
            }
            return true;

        }
        /// <summary>
        /// 分页函数
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="columns"></param>
        /// <param name="tablename"></param>
        /// <param name="pid"></param>
        /// <param name="order"></param>
        /// <param name="current"></param>
        /// <returns></returns>
        public DataTable GetPageData(int current,int pagesize,string columns,string tablename,string pid,string where,string order)
        {
            current = current-1>=0?(current-1):(0);
            string sql = string.Format("select top {0} {1} from {2} where 1=1 and {3} not in(select top {4}{3} from {2} where 1=1{5}  order by {6}){5} order by {6}", pagesize, columns, tablename, pid, current * pagesize,where, order);
            return GetTable(sql);
        }
        /// <summary>
        /// 分页存储过程的调用
        /// </summary>
        /// <param name="current"></param>
        /// <param name="pagesize"></param>
        /// <param name="columns"></param>
        /// <param name="tablename"></param>
        /// <param name="pid"></param>
        /// <param name="where"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public DataTable GetProcPageData(int current, int pagesize, string columns, string tablename, string pid, string where, string order,string ordertype)
        {
            SqlParameter[] pas = { new SqlParameter("@PageIndex", current), new SqlParameter("@PageSize", pagesize), new SqlParameter("@Columns", columns), new SqlParameter("@Tablename", tablename), new SqlParameter("@Where", where), new SqlParameter("@Order", order), new SqlParameter("@OrderType", ordertype), new SqlParameter("@Pid", pid)};
            return GetProcTable("Pages", pas);
            //current = current - 1 >= 0 ? (current - 1) : (0);
            //string sql = string.Format("select top {0} {1} from {2} where 1=1 and {3} not in(select top {4}{3} from {2} where 1=1{5}  order by {6}){5} order by {6}", pagesize, columns, tablename, pid, current * pagesize, where, order);
            //return GetTable(sql);
        }
        /// <summary>
        /// 分页存储过程的调用
        /// </summary>
        /// <param name="current"></param>
        /// <param name="pagesize"></param>
        /// <param name="columns"></param>
        /// <param name="tablename"></param>
        /// <param name="pid"></param>
        /// <param name="where"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public DataTable GetProcData(int current, int pagesize, string columns, string tablename, string pid, string where, string order,string resultCount, string distinct)
        {
            SqlParameter[] pas = { new SqlParameter("@TableNames", SqlDbType.NVarChar, 200), new SqlParameter("@PrimaryKey", SqlDbType.NVarChar, 100), new SqlParameter("@Order", SqlDbType.NVarChar, 200), new SqlParameter("@CurrentPage", SqlDbType.Int), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@Fields", SqlDbType.NVarChar, 800), new SqlParameter("@Filter", SqlDbType.NVarChar, 1000), new SqlParameter("@ResultCount", SqlDbType.NVarChar, 12), new SqlParameter("@distinct", SqlDbType.NVarChar, 12) };
            pas[0].Value = tablename;
            pas[1].Value = pid;
            pas[2].Value = order;
            pas[3].Value = current;
            pas[4].Value = pagesize;
            pas[5].Value = columns;
            pas[6].Value = where;
            pas[7].Value = resultCount;
            pas[8].Value = distinct;
            return this.GetProcTable("Pages", pas);
            //SqlParameter[] parameters = {
            //                                new SqlParameter("@TableNames",SqlDbType.VarChar,8000),
            //                                new SqlParameter("@PrimaryKey", SqlDbType.VarChar,8000),
            //                                new SqlParameter("@Order", SqlDbType.VarChar,8000),
            //                                new SqlParameter("@CurrentPage",SqlDbType.Int),
            //                                new SqlParameter("@PageSize", SqlDbType.Int),
            //                                new SqlParameter("@Fields",SqlDbType.VarChar,8000),
            //                                new SqlParameter("@Filter", SqlDbType.VarChar,8000),
            //                                new SqlParameter("@Group", SqlDbType.VarChar,8000)
            //                            };
            //parameters[0].Value = tablename;
            //parameters[1].Value = pid;
            //parameters[2].Value = order;
            //parameters[3].Value = current;
            //parameters[4].Value = pagesize;
            //parameters[5].Value = columns;
            //parameters[6].Value = where;
            //parameters[7].Value = "";
            //DataSet ds = DbHelperSQL.RunProcedure("Pages", parameters, "data");

            //return ds.Tables["data"];//
            //return GetProcTable("Pages", pas);
            //current = current - 1 >= 0 ? (current - 1) : (0);
            //string sql = string.Format("select top {0} {1} from {2} where 1=1 and {3} not in(select top {4}{3} from {2} where 1=1{5}  order by {6}){5} order by {6}", pagesize, columns, tablename, pid, current * pagesize, where, order);
            //return GetTable(sql);
        }
        /// <summary>
        /// 分页存储过程的调用
        /// </summary>
        /// <param name="current"></param>
        /// <param name="pagesize"></param>
        /// <param name="columns"></param>
        /// <param name="tablename"></param>
        /// <param name="pid"></param>
        /// <param name="where"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public DataTable GetProcAdminData(int current, int pagesize, string columns, string tablename, string pid, string where, string order,string resultCount, string distinct)
        {
            SqlParameter[] pas = { new SqlParameter("@TableNames", SqlDbType.NVarChar, 200), new SqlParameter("@PrimaryKey", SqlDbType.NVarChar, 100), new SqlParameter("@Order", SqlDbType.NVarChar, 200), new SqlParameter("@CurrentPage", SqlDbType.Int), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@Fields", SqlDbType.NVarChar, 800), new SqlParameter("@Filter", SqlDbType.NVarChar, 200), new SqlParameter("@ResultCount", SqlDbType.NVarChar, 24), new SqlParameter("@Distinct", SqlDbType.NVarChar, 12) };
            pas[0].Value = tablename;
            pas[1].Value = pid;
            pas[2].Value = order;
            pas[3].Value = current;
            pas[4].Value = pagesize;
            pas[5].Value = columns;
            pas[6].Value = where;
            pas[7].Value = resultCount;
            pas[8].Value = distinct;
            return this.GetProcTable("Pages", pas);
    
        }
        /// <summary>
        /// 打开连接
        /// </summary>
        public void OpenConn()
        {
            if (conn.State != ConnectionState.Open)
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {

                    this.ShowError(ex.Message);
                    return;
                }
            }
        }
        /// <summary>
        /// 关闭连接
        /// </summary>
        public void CloseConn()
        {
            if (conn.State != ConnectionState.Closed)
            {
                try
                {
                    conn.Close();
                
                }
                catch (Exception ex)
                {

                    this.ShowError(ex.Message);
                    return;
                }
            }
        }
        public void DisposeConn()
        {
            try
            {
                if (conn.State != ConnectionState.Closed)
                {
                    try
                    {
                        conn.Close();

                    }
                    catch (Exception ex)
                    {

                        this.ShowError(ex.Message);
                        return;
                    }
                }
            }
            catch
            {
 
            }
        }
    
        /// <summary>
        /// 弹出错误的信息
        /// </summary>
        /// <param name="err"></param>
        public void ShowError(string err)
        {
          //  System.Web..Current.Response.Write(Script(err, ""));
        }
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="err"></param>
        public void ShowMessage(string mes, string loc)
        {
           // System.Web.HttpContext.Current.Response.Write(Script(mes, loc));
        }
        /// <summary>
        /// javascript脚本
        /// </summary>
        /// <param name="mess"></param>
        /// <param name="loc"></param>
        /// <returns></returns>
        public string Script(string mess, string loc)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script language='javascript'>");
            sb.Append("alert('");
            sb.Append(mess);
            sb.Append("');");
            sb.Append(loc);
            sb.Append("</script>");
            return sb.ToString();

        }
        /// <summary>
        /// 弹出错误的信息
        /// </summary>
        /// <param name="err"></param>
        public static void ShowErrorstatic(string err)
        {
           // System.Web.HttpContext.Current.Response.Write(DbAccess.Scriptstatic(err, ""));
        }
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="err"></param>
        public static void ShowMessagestatic(string mes, string loc)
        {
            //System.Web.HttpContext.Current.Response.Write(DbAccess.Scriptstatic(mes, loc));
        }
         //<summary>
         //javascript脚本
         //</summary>
         //<param name="mess"></param>
         //<param name="loc"></param>
         //<returns></returns>
        public static string Scriptstatic(string mess, string loc)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script language='javascript'>");
            sb.Append("alert('");
            sb.Append(mess);
            sb.Append("');");
            sb.Append(loc);
            sb.Append("</script>");
            return sb.ToString();

        }
        public SqlParameter[] MakeParameters(params string[] pas)
        {
            SqlParameter[] tempPas = new SqlParameter[pas.Length / 2];
            if (pas.Length % 2 == 0)
            {
                for (int i = 0; i < pas.Length / 2; i++)
                {
                    tempPas[i] = new SqlParameter(pas[i * 2], pas[i * 2 + 1]);
                }
            }
            return tempPas;

        }
 
    }
    public class SqlTranModel
    {
        private string _sql;
        public string Sql
        {
            set { this._sql = value; }
            get { return this._sql; }
        }
        private SqlParameter[] _pas;
        public SqlParameter[] Pas
        {
            set { this._pas = value; }
            get { return this._pas; }
        }
    }
}

分享到:
评论

相关推荐

    c# SQL server数据库连接类

    用于描述与SQL SERVER连接时用到的一些常用函数,可实现大多数操作

    C#SqlServer数据库链接帮助类

    C#SqlServer数据库链接帮助类

    C# SQL Server数据库连接

    本教程将通过一个简单示例,讲解如何使用C#连接到SQL Server数据库,执行查询并显示结果。 首先,你需要在C#项目中引入System.Data.SqlClient命名空间,这是用于与SQL Server交互的关键库。在代码文件顶部添加以下...

    C# SQL Server数据库操作DLL

    1. **数据库连接**:DLL通常会提供一个类,如`DBConnection`,用于管理到SQL Server数据库的连接。这个类可能包含`Open()`、`Close()`方法,以打开和关闭数据库连接,以及`ConnectionString`属性,用于设置连接字符...

    C#连接SqlServer数据库帮助类,SqlServerHelp

    本篇将详细探讨如何使用C#连接和操作SQL Server数据库,以`SqlServerHelp`类为例,阐述其中的关键知识点。 首先,`SqlServerHelp`类是为简化与SQL Server数据库的交互而设计的。在C#中,我们通常使用ADO.NET库,它...

    SQL Server数据库备份与恢复(C#代码示例)

    C#中进行SQL Server数据库备份通常涉及以下步骤: 1. 连接数据库:使用SqlConnection类建立到SQL Server实例的连接。 2. 构建备份命令:创建SqlCommand对象,并设置其CommandText属性为SQL备份语句,例如`BACKUP ...

    C#远程连接SQLserver 数据库

    在C#中,通过SqlConnection类来创建和管理与SQL Server的连接,而SqlDataAdapter则用于填充DataSet和执行SQL命令。 在远程连接SQL Server数据库时,关键在于构建正确的连接字符串。例如,在上述代码中,连接字符串...

    C#实现异步连接Sql Server数据库的方法

    在C#编程中,异步连接SQL Server数据库是提高应用程序性能和用户体验的关键技术。这是因为异步操作允许程序在等待数据库响应时执行其他任务,而不是阻塞主线程,从而避免了UI冻结或整体性能下降。本篇文章将深入探讨...

    c#数据库sqlserver连接公共类的实现

    以上就是基于C#的SQL Server数据库连接公共类的基本实现,涵盖了打开和关闭数据库、创建SQL命令、执行SQL语句以及将数据转换为DataTable的主要功能。在实际应用中,可能还需要考虑异常处理、事务管理、连接池等高级...

    C# 开发SQLSERVER数据库自动建表

    标题“C# 开发SQLSERVER数据库自动建表”表明我们将讨论一个使用C#开发的程序,该程序可以自动化创建SQL Server数据库中的表结构。这个功能对于数据导入、系统初始化或简化数据库管理流程非常有用。 描述中提到,该...

    C#操作SQL Server数据库通用类.doc

    "C#操作SQL Server数据库通用类" 本文档中提供了一个通用的C#类,用于访问SQL Server数据库。该类名为DataAccess,位于insurer命名空间中。该类提供了基本的数据库操作,包括打开和关闭数据库连接、执行存储过程、...

    Visual C#的SQL Server数据库连接编程

    "Visual C# 的 SQL Server 数据库连接编程" Visual C# 的 SQL Server 数据库连接编程是指在 C# 编程中使用 SQL Server 数据库连接的技术。该技术可以使得 C# 程序能够与 SQL Server 数据库进行交互,实现数据的存储...

    c#和SQL Server 数据库连接

    C#连接数据库,我们可以将代码打成包,到时候直接引用就可以了。输入正确的参数就可以使用了。

    c# sql server数据库操作源程序,集连接,显示,修改,查询,导入/导出EXECL。

    c# 编写的winform 操作sql server数据库操作源程序,程序设计技巧性强,集sql server数据库操作之大全,跨窗体增加,修改数据,可连接,显示,修改,查询,导入/导出EXECL。可访问本地数据库,也可访问局域网数据库...

    C#操作SQL SERVER数据库的类

    在本场景中,我们关注的是如何使用C#来操作SQL SERVER数据库。这个类库提供了一个简便的方法来执行常见的数据库操作,如查询、插入、更新和删除数据。 首先,我们来看`IniFiles.cs`文件,这通常包含了处理INI配置...

    C#连接SQLServer数据库

    本主题将深入探讨如何使用C#连接到SQL Server数据库,并执行基本的数据操作,如增、删、改。 首先,要理解C#连接SQL Server数据库的核心组件是ADO.NET,它是.NET Framework的一部分,提供了与各种数据库进行交互的...

    MFC连接SQL Server数据库

    MFC连接SQL Server数据库 MFC(Microsoft Foundation Classes)是一种基于C++的应用程序框架,广泛应用于Windows平台的桌面应用程序开发。其中一个重要的应用场景是连接数据库,以便进行数据存储和检索。本文将详细...

    c# 模拟sql server数据库(对DataGridView的操作)

    在本教程中,我们将聚焦于如何使用C#模拟SQL Server数据库,并结合DataGridView控件来展示数据。首先,我们需要理解几个核心概念: 1. **C#**:这是一种面向对象的编程语言,由微软公司开发,广泛应用于Windows应用...

    C# SqlServer 数据库实体生成工具1.0

    标题 "C# SqlServer 数据库实体生成工具1.0" 指的是一款基于C#编程语言开发的软件工具,其主要功能是自动生成与SQL Server数据库中的表结构相对应的实体类。这类工具通常被开发者用来提高开发效率,因为它可以自动将...

Global site tag (gtag.js) - Google Analytics