资源简介
C#的sqlserver数据库操作封装类,封装了sql语句的查询、修改、插入、删除操作,以及存储过程的执行,包括有输入、输出参数的存储过程,存储过程的执行无需输入任何参数名称,只需输入参数值即可。同时封装了大批量数据的更新操作,是普通DataAdapter和Command批量操作效率的30倍以上。
代码片段和文件信息
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
namespace SqlHelper
{
public class SqlCompose
{
#region 构造函数
///
/// 构造函数
///
///
public SqlCompose(string connStr)
{
this.connStr = connStr;
}
#endregion
#region 变量
//数据库连接对象
private SqlConnection _connection = null;
//数据库连接字符串
private string connStr = string.Empty;
#endregion
#region 属性
///
/// 数据库连接对象
///
private SqlConnection Connnection
{
get
{
if (this._connection == null || this._connection.State == ConnectionState.Broken || this._connection.State == ConnectionState.Closed)
{
this._connection = new SqlConnection(connStr);
}
return this._connection;
}
}
#endregion
#region 方法
#region BuildQueryCommand
///
/// 创建Command对象
///
/// sql语句或存储过程名称
/// 是否是存储过程
/// 输入参数集合
/// 输出参数集合
///
private SqlCommand BuildQueryCommand(string sqlOrprocedureName bool isProcedure object[] inParameters object[] outParameters)
{
SqlCommand command = new SqlCommand(sqlOrprocedureName this.Connnection);
command.CommandType = isProcedure ? CommandType.StoredProcedure : CommandType.Text;
if (isProcedure && ((inParameters != null && inParameters.Length > 0) || (outParameters != null && outParameters.Length > 0)))
{
//获取存储过程参数,获取参数顺序为,存储过程执行返回值ReturnValue>输入参数Input>输入输出参数InputOutput>输出参数Output。
//其中Output为纯输出参数,不用传参,但sqlserver存储过程里定义的输出参数,在C#中一般为InputOutput类型,除非存储过程中定义的是返回值而非输出参数。
command.Connection.Open();
SqlCommandBuilder.DeriveParameters(command);
command.Connection.Close();
try
{
//存储过程参数赋值
for (int i = 1; i < command.Parameters.Count; i++)
{
if (inParameters != null && inParameters.Length > 0 && i <= inParameters.Length)
{
command.Parameters[i].Value = inParameters[i - 1];
}
else if (outParameters != null && outParameters.Length > 0)
{
- 上一篇:C#开发的记忆力测试游戏
- 下一篇:C#微信公众平台开发实用类库
相关资源
- C#微信公众平台开发实用类库
- C#开发的记忆力测试游戏
- C# 图片添加注释
- C#中GDI+实现简单二维矢量图编辑器教
- c#写的简单备忘录
- C#酒店管理系统源代码
- C# 通过 Renci.SshNet 实现SFTP数据传输
- C#中子窗体调用主窗口控件的简单
- C# 自定义带搜索下拉框
- C#控制GPIO
- C# 三角形网格等值线绘制案例源码
- c#连接MYSQL数据库Mysql.data.dll 5.1.62
- C#实现的数字图像边缘检测程序
- 端口扫描程序、学习demo
- 汉诺塔动态演示程序C#完整项目
- 类QQ(P2P)聊天系统的原理与C#实现
- 曲线拟合&&线性回归C#)
- 基于socket的c#实现的五子棋
- 用C#写的高斯滤波源代码
- C#开发的网络调试助手包括TCP和UDP客户
- C# 表达式解析器源代码(修正)
- Visual.C#2010从入门到精通 光盘源码
- C# 读取电能表度数 DLT645协议
- C# HtmlToWord 将HTML文件转换成word文档
- 最小二乘法圆拟合算法C#实现
- C# 基于 directinput 操控手柄
- .net(c#)支付宝接口源代码(亲测可
- C#生成机器码,让软件实现注册功能
- C#+SQLServer2000学生管理系统源代码
- C#控件随窗口变化而变化,同时panel中
评论
共有 条评论