dbhelp.cs
来自「一个 用Ajax实现聊天室的简单例子 不全的地方指点」· CS 代码 · 共 58 行
CS
58 行
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 + =
减小字号Ctrl + -
显示快捷键?