📄 dbhelp.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 + -