⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbhelp.cs

📁 一个 用Ajax实现聊天室的简单例子 不全的地方指点
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ChatDAL
{
    public class DBHelper
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Chat"].ToString());
        SqlCommand ps;

        //执行增,删,改
        public int getRow(string sql)
        {
            int row = 0;
            try
            {
                if (con.State == ConnectionState.Closed)
                    con.Open();
                ps = new SqlCommand(sql, con);
                row = ps.ExecuteNonQuery();
            }
            catch { }
            finally
            {
                con.Close();
            }
            return row;
        }

        //执行查询
        public SqlDataReader getRead(string sql)
        {
            SqlDataReader rs = null;
            try
            {
                if (con.State == ConnectionState.Closed)
                    con.Open();
                ps = new SqlCommand(sql, con);
                rs = ps.ExecuteReader();
            }
            catch { }
            return rs;
        }

        //关闭连接
        public void closeCon()
        {
            if (con.State == ConnectionState.Open)
                con.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -