• 大小: 2.02MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-21
  • 语言: C#
  • 标签: 案例  

资源简介

该案例是北大青鸟《使用C#语言开发数据库应用系统》第8章的项目案例,这是我自己的做的,给大家参考参考,有什么不足之处,还望各位前辈多多指点!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;

namespace SuperCommodityManager
{
    public class DBHelper
    {
        //通过读取配置文件获得连接字符串
        private static readonly string connString = ConfigurationManager.ConnectionStrings[“strConn“].ToString();

        //创建Connection对象
        private SqlConnection conn;
        public SqlConnection Conn
        {
            get
            {
                if (conn == null)
                {
                    conn = new SqlConnection(connString);
                }
                return conn;
            }
            set { conn = value; }
        }

        //打开连接
        public void OpenConnection()
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            if (conn.State == ConnectionState.Broken)
            {
                conn.Close();
                conn.Open();
            }
        }

        //关闭连接
        public void CloseConnection()
        {
            if (conn.State == ConnectionState.Open || conn.State == ConnectionState.Broken)
            {
                conn.Close();
            }
        }


        /// 
        /// 得到首行首列的值
        /// 

        /// 
        /// 
        public object GetExecuteScalar(string sql)
        {
            SqlCommand comm = new SqlCommand(sql Conn);
            object data = null;
            try
            {
                OpenConnection();   //打开连接
                data = comm.ExecuteScalar();    //返回单个值

            }
            catch (Exception ex)
            {
                MessageBox.Show(“出现异常!“ + ex.Message);
                data = null;
            }
            finally
            {
                CloseConnection();  //关闭连接
            }
            return data;
        }

        /// 
        /// 得到受影响行数
        /// 

        /// 
        /// 
        public int GetExecuteNonQuery(string sql)
        {
            SqlCommand comm = new SqlCommand(sql Conn);
            int num = 0;
            try
            {
                OpenConnection();   //打开连接
                num = comm.ExecuteNonQuery();   //返回行的语句

            }
            catch (Exception ex)
            {
                MessageBox.Show(“出现异常!“ + ex.Message);
            }
            finally
            {
                CloseConnection();  //关闭连接
            }
            return num;
        }

        /// 
        /// 得到多行多列的值
        /// 

        /// 
        /// 
        public SqlDataReader GetExecuteReader(string sql)
        {
            S

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6926  2011-12-29 23:03  SuperCommodityManager\SuperCommodityManager\obj\x86\Debug\SuperCommodityManager.csproj.FileListAbsolute.txt

     文件     234496  2011-12-29 23:03  SuperCommodityManager\SuperCommodityManager\bin\Debug\SuperCommodityManager.exe

     文件     234496  2011-12-29 23:03  SuperCommodityManager\SuperCommodityManager\obj\x86\Debug\SuperCommodityManager.exe

     文件      11600  2011-12-29 23:03  SuperCommodityManager\SuperCommodityManager\bin\Debug\SuperCommodityManager.vshost.exe

     文件       4440  2011-12-28 13:50  SuperCommodityManager\SuperCommodityManager\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6600  2011-12-29 23:03  SuperCommodityManager\SuperCommodityManager\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       8609  2011-12-28 15:10  SuperCommodityManager\SuperCommodityManager\obj\x86\Debug\ResolveAssemblyReference.cache

     文件        225  2011-12-28 16:41  SuperCommodityManager\SuperCommodityManager\App.config

     文件        225  2011-12-28 16:41  SuperCommodityManager\SuperCommodityManager\bin\Debug\SuperCommodityManager.exe.config

     文件        225  2011-12-28 16:41  SuperCommodityManager\SuperCommodityManager\bin\Debug\SuperCommodityManager.vshost.exe.config

     文件       1386  2011-12-27 08:27  SuperCommodityManager\SuperCommodityManager\Properties\AssemblyInfo.cs

     文件       3571  2011-12-27 08:31  SuperCommodityManager\SuperCommodityManager\DBHelper.cs

     文件        952  2011-12-28 17:33  SuperCommodityManager\SuperCommodityManager\FrmAbout.cs

     文件       4533  2011-12-28 17:33  SuperCommodityManager\SuperCommodityManager\FrmAbout.Designer.cs

     文件       4871  2011-12-28 14:50  SuperCommodityManager\SuperCommodityManager\FrmCommodityList.cs

     文件      15212  2011-12-28 00:55  SuperCommodityManager\SuperCommodityManager\FrmCommodityList.Designer.cs

     文件       3778  2011-12-28 16:31  SuperCommodityManager\SuperCommodityManager\FrmCommoditySort.cs

     文件       9067  2011-12-28 16:27  SuperCommodityManager\SuperCommodityManager\FrmCommoditySort.Designer.cs

     文件       3703  2011-12-28 16:26  SuperCommodityManager\SuperCommodityManager\FrmEditCommoditySort.cs

     文件       4477  2011-12-28 16:17  SuperCommodityManager\SuperCommodityManager\FrmEditCommoditySort.Designer.cs

     文件       7281  2011-12-28 16:27  SuperCommodityManager\SuperCommodityManager\FrmEditGoodsInfo.cs

     文件      10653  2011-12-28 00:21  SuperCommodityManager\SuperCommodityManager\FrmEditGoodsInfo.Designer.cs

     文件       3220  2011-12-27 10:33  SuperCommodityManager\SuperCommodityManager\FrmLogin.cs

     文件       6830  2011-12-27 09:39  SuperCommodityManager\SuperCommodityManager\FrmLogin.Designer.cs

     文件       4046  2011-12-28 16:34  SuperCommodityManager\SuperCommodityManager\FrmModifyPwd.cs

     文件       6430  2011-12-27 12:00  SuperCommodityManager\SuperCommodityManager\FrmModifyPwd.Designer.cs

     文件       2493  2011-12-28 15:37  SuperCommodityManager\SuperCommodityManager\FrmSuperCommodity.cs

     文件       9541  2011-12-28 15:37  SuperCommodityManager\SuperCommodityManager\FrmSuperCommodity.Designer.cs

     文件        505  2011-12-28 16:41  SuperCommodityManager\SuperCommodityManager\Program.cs

     文件       2890  2011-12-27 08:27  SuperCommodityManager\SuperCommodityManager\Properties\Resources.Designer.cs

............此处省略81个文件信息

评论

共有 条评论