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

C# SQL数据库操作通用类


C# SQL数据库操作通用类
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace Framework.DataBase
{
///
/// 通用数据库类
///
public class DataBase
{
private string ConnStr = null;
public DataBase()
{
   ConnStr = ConfigurationSettings.AppSettings["ConnStr"];
}
public DataBase(string Str)
{
   try
   {
    this.ConnStr = Str;
   }
   catch(Exception ex)
   {
    throw ex;
   }
}
///
/// 返回connection对象
///
///
public SqlConnection ReturnConn()
{
   SqlConnection Conn = new SqlConnection(ConnStr);
   Conn.Open();
   return Conn;
}
public void Dispose(SqlConnection Conn)
{
   if(Conn!=null)
   {
    Conn.Close();
    Conn.Dispose();
   }
}
///
/// 运行SQL语句
///
///
public void RunProc(string SQL)
{
   SqlConnection Conn;
   Conn = new SqlConnection(ConnStr);
   Conn.Open();
   SqlCommand Cmd ;
   Cmd = CreateCmd(SQL, Conn);
   try
   {
    Cmd.ExecuteNonQuery();
   }
   catch
   {
    throw new Exception(SQL);
   }
   Dispose(Conn);
   return;
}   
///
   /// 运行SQL语句返回DataReader
///
    ///
    /// SqlDataReader对象.
public SqlDataReader RunProcGetReader(string SQL)
{
   SqlConnection Conn;
   Conn = new SqlConnection(ConnStr);
   Conn.Open();
   SqlCommand Cmd ;
   Cmd = CreateCmd(SQL, Conn);
   SqlDataReader Dr;
   try
   {
    Dr = Cmd.ExecuteReader(CommandBehavior.Default);
   }
catch


相关文档:

SQL 2008 怎样还原数据库?

因现在的工作需要,
我得从WinForm的平台,
转型到WebForm的页面。
有一年多没有接触SQL Server了,
虽然大学时有点基础,
但也忘记得差不多了。
因为Asp.net型的B/S网站和WinForm的还是有点不同,
现在工作起来不是那么得心应手。
温故而知新,
就把以前实习时做的的网站源代码拿出来看看。
因为要用到SQL 2005S ......

SQL SERVER字段类型说明

 
bit:0或1的整型数字
int:从-2^31(-2,147,483,648)到2^31(2,147,483,647)的整型数字
smallint:从-2^15(-32,768)到2^15(32,767)的整型数字
tinyint:从0到255的整型数字

decimal:从-10^38到10^38-1的定精度与有效位数的数字
numeric:decimal的同义词

money:从-2^63(-922,337,203,685,477.580 ......

SQL语句

1. 说明:复制表(只复制结构,源表名:a,新表名:b)
SQL: select * into b from a where 1<>1;
        2. 说明:拷贝表(拷贝数据,源表名:a,目标表名:b)
SQL: insert into b(a, b, c) select d, e, f from b;
        3. 说明: ......

SQL SERVER

sql server分布式事务解决方案
适用环境
操作系统:windows 2003
数据库:sql server 2000/sql server 2005
使用链接服务器进行远程数据库访问的情况
一、  问题现象
在执行分布式事务时,在sql server 2005下收到如下错误:
消息 7391,级别 16,状态 2,过程 xxxxx,第 16 行
无法执行该操作,因为链接服务 ......

sql 备份和删除

备份
DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR,getdate(),120)
set @strPath='hq'+rtrim(left(replace(@strPath,'-',''),8))
set @strPath = 'D:\sqlback\mydb\' + @strPath + '.bak'
BACKUP DATABASE [mydb] TO DISK = @strPath WITH NOFORMAT, NOINIT, NAME = N'mydb-完整 数据库 备份', ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号