易截截图软件、单文件、免安装、纯绿色、仅160KB

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();
}
}


相关文档:

【C#】XSLT转换XML实例

产品几年前使用ASP,后来升级到.Net 1.1,再升级到2.0,一直都有用XSLT转换XML生成网页的方式,稍微整理下。
    XML file:
<?xml version="1.0" encoding="utf-8" ?>
<ric>
  <catalog>
    <book price ......

c# 程序只运行一次的处理方法

方法一:遍历正在有相同名字运行的例程
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DHPSS.COM
{
/// <summary>
/// c#程序只运行一次,C#例程只运行一次
/// http://blog.csdn.net/nnsw ......

C#中结构与类的区别

一.类与结构的示例比较:
结构示例:
public struct Person
{
string Name;
int height;
int weight
public bool overWeight()
{
//implement something
}
}
类示例:
public class TestTime
{
int hours;
int minutes;
int seconds;
public void passtime()
{
//implementation ......

C#开发WPF/Silverlight动画及游戏系列教程(转)

C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):目录
本系列教程的示例代码下载(感谢 银光中国 提供资源分流):
第一部分源码:WPFGameTutorial_PartI(1-20节)
第二部分源码:WPFGameTutorial_PartII(21-26节)
第三部分源码:WPFGameTutorial_PartIII(27-30节)
第四部分源码:WPFGameTutorial_PartI ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号