📄 clsdbcontrol.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
namespace OptDB.ClsDB
{
class ClsDBControl
{
private SqlConnection con;
SqlDataReader selectresult = null;
#region//生成连接对象
public SqlConnection ConDB()
{
con = new SqlConnection("server =(local);Trusted_Connection=SSPI;Database=wupeng;Enlist=false");
if (con.State == ConnectionState.Closed)
{
con.Open();
}
return con;
}
#endregion
public bool insertDB(String sql)
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
cmd.CommandText = sql;//设置SQL语句
cmd.Connection = ConDB();//调用打开数据库连接方法
cmd.ExecuteNonQuery();//执行
return true;
}
catch
{
return false;
}
}
}
public SqlDataReader cheat(string sql)
{
try
{
con = new SqlConnection("server =(local);Trusted_Connection=SSPI;Database=wupeng;Enlist=false");
con.Open();
SqlCommand sqlcommand = new SqlCommand(sql, con);
sqlcommand.CommandType = CommandType.Text;
selectresult = sqlcommand.ExecuteReader();
}
catch (SqlException ex)
{
ex.Message.ToString();
}
return selectresult;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -