C#——访问SQL Server 2005公共类
下面是我总结出来的一个数据库访问公共类,基于ADO.NET,C#的,其中,以重载的方式实现使用存属过程的接口和不用存储过程的接口,如有不妥请大家指正,谢谢~
作者:shinehoo
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace shinehoo.db
{
/// <summary>
/// 对数据库的一些公共操作
/// </summary>
public class DBOperate
{
/// <summary>
/// 建立数据库连接
/// </summary>
/// <returns>返回SqlConnection对象</returns>
public static SqlConnection getConnection()
{
SqlConnection myCon;
try
{
string strSqlCon = "Data Source = SHINEHOO-PC\\SQLEXPRESS; Initial Catalog = ShineHoo_DB; Integrated Security = True";
//SqlConnection类用来连接数据库
myCon = new SqlConnection(strSqlCon);
}
catch (Exception e)
{
throw e;
}
return myCon;
}
/// <summary>
/// 执行SqlCommand命令
/// </summary>
/// <param name="strSqlCommand">SQL语句</param>
public static void getCommand(string strSqlCommand)
{
SqlConnection sqlcon = getConnection();
try
{
//SqlConnection类的Open()方法用来打开数据库连接
sqlcon.Open();
//声明将对数据库执行一个SQL语句或存储过程
SqlCommand sqlcom = new SqlCommand(strSqlCommand, sqlcon);
//执行SqlCommand命令
sqlcom.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
//关闭数据库连接
sqlcon.Close();
//sqlcon.Dispose();
}
}
相关文档:
string error_syntaxfromSQL, error_create
string new_sql, new_syntax
new_sql = 'SELECT emp_data.emp_id, ' &
& ......
public string WriteXML(string[] values, int flag)
{
//如果flag==0则为第一次运行需要初始化XML文件
if (flag == 0)
{
//生在随机文件名
string dateName = System.DateTime.Now.ToString("yyyyMMddHHmmss");
......
先声明,我不是这方面的专家,只是干软件四个月不知天有多高地有多硬的小孩子
首先,类型转换是有一定开销的
我试过这样的代码:这是一个控制台应用程序的Program类的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 类型转换的开销
{
class Program
......
c#事务回滚(转)
作者:xue5ya 来源:博客园 发布时间:2009-03-20 16:08 阅读:263 次 原文链接 [收藏]
Code
public void UpdateContactTableByDataSet(DataSet ds,string strTblName)
{
......
刚接触.net 时就听说 Reflector这个强大反编译工具呢,只是一直没有去使用他. 今天update跟我说Reflector如何,如何有用,用的如何,如何爽,还得意的说反编译了不少DLL...本来本人对新鲜事就非常有兴趣,听他这么一说.决定试一试这个传说中的工具.
我用的版本是4.1.84.0,以,把自己编写DLL反编译了一下,反编译后的代码 ......