C# database封装
来源:互联网 发布:神经网络算法过程 编辑:程序博客网 时间:2024/05/16 09:44
public class database
{
public static string GetConnectionString()
{
string conStr = ConfigurationManager.ConnectionStrings["BMSConnectionString"].ConnectionString;
return conStr;
}
public static int ExecuteNonQuery(string commandText)
{
try
{
SqlConnection conn;
SqlCommand command;
conn = new SqlConnection();
conn.ConnectionString = GetConnectionString();
command = new SqlCommand();
command.CommandText = commandText;
command.CommandType = CommandType.Text;
command.Connection = conn;
command.Connection.Open();
int rs = command.ExecuteNonQuery();
}
catch(SqlException ex)
{
throw ex;
}
finally
{
command.Connection.Close();
command.Dispose();
conn.Dispose();
return rs;
}
}
public static DataTable ExecuteDataTable(string commandText)
{
try
{
SqlConnection conn;
SqlCommand command;
SqlDataAdapter sda;
DataTable table = new DataTable();
conn = new SqlConnection();
conn.ConnectionString = GetConnectionString();
command = new SqlCommand();
command.CommandText = commandText;
command.CommandType = CommandType.Text;
command.Connection = conn;
command.Connection.Open();
sda = new SqlDataAdapter();
sda.SelectCommand = command;
sda.Fill(table);
}
catch (SqlException ex)
{
throw ex;
}
finally
{
sda.dispose();
command.Connection.Close();
command.Dispose();
conn.Dispose();
return table;
}
}
}
- C# database封装
- C# 封装
- C# 封装
- c# 封装
- c# 封装
- C#封装
- C#封装
- c#封装
- c#封装
- C# 封装
- C#封装
- c#封装
- c#封装
- C#封装
- C# 封装
- Mastering C# database programming
- C# DataBase类
- c# Database Connectionstrings
- OpenCms “傻瓜建站”之 templateTwo 模块——概述篇
- Grails探索之Template
- VS2008安装失败原因!
- [转] Unsigned VS signed
- 常用认证技术
- C# database封装
- 职场纵横:IT职位全面解析(计算机类要找工作的朋友多看看)
- PB HOOKAPI函数
- serialVersionUID的作用
- ISAPI_Rewrite如何忽略大小写
- PKU2828 Buy Tickets [1WA 2AC][08.08.22]
- BBS项目初步总结(续)
- POI导出EXCEL经典实现
- 行货手机和水货手机究竟啥区别?