资源简介
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# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- 超市进销存管理系统 Sqlserver 数据库文
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
评论
共有 条评论