没有合适的资源?快使用搜索试试~ 我知道了~
c# 操作MSSQL数据库通用类
4星 · 超过85%的资源 需积分: 11 38 下载量 183 浏览量
2010-04-02
15:45:48
上传
评论
收藏 22KB TXT 举报
温馨提示
试读
18页
c# 操作MSSQL数据库通用类c# 操作MSSQL数据库通用类c# 操作MSSQL数据库通用类
资源推荐
资源详情
资源评论
public class SystemDB
{
public SystemDB()
{
//
// 此处: 添加构造函数
//
}
public static string ConnectionString = "Data Source=数据库地址;Initial Catalog=数据库名称;Persist Security Info=True;User ID=帐号;Password=密码";
//根据sql语句返回一个DataSet
#region GetDataSet
public DataSet GetDataSet(string sql)
{
SqlCommand sqlcom = new SqlCommand();
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
PrepareCommand(sqlcom, conn, CommandType.Text, sql);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sda.Fill(ds);
sqlcom.Parameters.Clear();
return ds;
}
}
#endregion
//根据sql语句返回一个SqlDataReader
#region ExecSqlDataReader
public SqlDataReader ExecSqlDataReader(string sql)
{
{
public SystemDB()
{
//
// 此处: 添加构造函数
//
}
public static string ConnectionString = "Data Source=数据库地址;Initial Catalog=数据库名称;Persist Security Info=True;User ID=帐号;Password=密码";
//根据sql语句返回一个DataSet
#region GetDataSet
public DataSet GetDataSet(string sql)
{
SqlCommand sqlcom = new SqlCommand();
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
PrepareCommand(sqlcom, conn, CommandType.Text, sql);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sda.Fill(ds);
sqlcom.Parameters.Clear();
return ds;
}
}
#endregion
//根据sql语句返回一个SqlDataReader
#region ExecSqlDataReader
public SqlDataReader ExecSqlDataReader(string sql)
{
SqlCommand sqlcom = new SqlCommand();
SqlConnection conn = new SqlConnection(ConnectionString);
try
{
PrepareCommand(sqlcom, conn, CommandType.Text, sql);
SqlDataReader sdr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);
sqlcom.Parameters.Clear();
return sdr;
}
catch (Exception ex)
{
conn.Close();
throw ex;
}
}
#endregion
//执行sql语句,返回影响行数
#region ExecCommand
public int ExecCommand(string sql)
{
SqlCommand sqlcom = new SqlCommand();
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
PrepareCommand(sqlcom, conn, CommandType.Text, sql);
int rtn = sqlcom.ExecuteNonQuery();
sqlcom.Parameters.Clear();
return rtn;
}
}
#endregion
SqlConnection conn = new SqlConnection(ConnectionString);
try
{
PrepareCommand(sqlcom, conn, CommandType.Text, sql);
SqlDataReader sdr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);
sqlcom.Parameters.Clear();
return sdr;
}
catch (Exception ex)
{
conn.Close();
throw ex;
}
}
#endregion
//执行sql语句,返回影响行数
#region ExecCommand
public int ExecCommand(string sql)
{
SqlCommand sqlcom = new SqlCommand();
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
PrepareCommand(sqlcom, conn, CommandType.Text, sql);
int rtn = sqlcom.ExecuteNonQuery();
sqlcom.Parameters.Clear();
return rtn;
}
}
#endregion
剩余17页未读,继续阅读
资源评论
- weihahaha2014-04-25txt文档 好麻烦,我弄好了发个例子,
- v88182014-01-02可以直接用,还是源码格式,
- luis_132013-03-07很实用的东西~
冷锋-wayne
- 粉丝: 1
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功