您的位置:首页 > 数据库

数据库操作类的封装

2009-09-10 17:54 169 查看
public static string conString = @"Server=localhost;Integrated Security=True; Database=northwind";
1. 执行Sql语句, 返回受影响的行数

Code
//执行一条计算查询结果语句,返回查询结果(object)
public static object GetSingle(string strSql)
{
SqlConnection thisConnection = new SqlConnection(conString);
SqlCommand thisCommand = new SqlCommand(strSql, thisConnection);
thisConnection.Open();
object obj = thisCommand.ExecuteScalar();
if((Object.Equals(obj,null))||(Object.Equals(obj,System.DBNull.Value)))
{
return null;
}
else
{
return obj;
}
}调用方法:
string strSql = @"select * from Customers";
string num = Utility.GetSingle(strSql).ToString();
5. 带参数, 执行SQL语句, 返回影响的记录数
..............
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: