文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > DBHelper存储过程
侵权投诉

DBHelper存储过程

DBHelper存储过程

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DAL
{
public class DBHelper
{
protected SqlConnection conn = null;
protected SqlCommand comm = null;
protected SqlDataAdapter DA = null;
protected SqlDataReader DR = null;

public DBHelper()
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["ConString"].ToString());
}

/// <summary>
/// 返回一个DataTable数据集
/// </summary>
/// <param name="sql">sql查询语句</param>
protected DataTable GetDataTable(string sql)
{
DA = new SqlDataAdapter(sql, conn);
DataTable DT = new DataTable();
DA.Fill(DT);
return DT;
}

/// <summary>
/// 返回指定条件的DataTable数据集
/// </summary>
/// <param name="sql">Sql查询语句</param>
/// <param name="parameter">查询条件</param>
protected DataTable GetDataTable(string sql, SqlParameter parameter)
{
comm = new SqlCommand(sql, conn);
comm.Parameters.Add(parameter);
DA = new SqlDataAdapter();
DA.SelectCommand = comm;
DataTable DT = new DataTable();
DA.Fill(DT);
return DT;
}

/// <summary>
/// 返回指定条件的DataTable数据集
/// </summary>
/// <param name="sql">Sql查询语句</param>
/// <param name="parameters">查询条件</param>
protected DataTable GetDataTable(string sql, SqlParameter[] parameters)
{
comm = new SqlCommand(sql, conn);
foreach (SqlParameter parameter in parameters)
{
comm.Parameters.Add(parameter);
}
DA = new SqlDataAdapter();
DA.SelectCommand = comm;
DataTable DT = new DataTable();
DA.Fill(DT);
return DT;
}

/// <summary>
/// 返回单个数据
/// </summary>
/// <param name="sql">sql查询语句</param>
protected object GetData(string sql)
{
comm = new SqlCommand(sql, conn);
try
{
conn.Open();
return comm.ExecuteScalar();
}
catch (SqlException)
{
return null;
}
catch (InvalidOperationException)
{
return null;
}
catch
{
return null;
}
finally
{
conn.Close();
}
}

/// <summary>
/// 返回指定条件的单个数据
/// </summary>
/

第1页

你可能喜欢

  • 存储过程
  • 数据库的存储过程
  • 数据存储系统
  • 存储过程实例
  • 存储系统
  • 存储方案

热门文档

相关文档

  • DBHelper

    DBHelper_IT/计算机_专业资料。能用存储过程的DBHelperusing System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System....

  • DBHelper类

    (cmd); //2)执行存储过程 // DbHelper db = new DbHelper(); // DbCommand cmd = db.GetStoredProcCommond("t1_insert"); // db.AddInParameter(cmd, ...

  • SQL 操作DBHelper

    using System; using System.Data; using System.Data.Common; using System.Configuration; public class DbHelper { private static string dbProviderName = ...

  • SqlDBHelper常用方法

    SqlDBHelper常用方法_IT/计算机_专业资料。SqlDBHelper常用方法/*===...语句或存储过程名称 /// T-SQL 语句类别 /// 参数列表 /// <returns>返回值为:true...

  • DBHelper带注释

    DBHelper(C#版本 版本) 版本这个是我网上找的,觉得不错的一个 DBHelper 类,下面是作者话: //微软的企业库中有一个非常不错的数据操作类了.但是,不少公司(...

  • 微软DBHelper类

    using System; using System.Data; using System.Data.Common; using System.Configuration; public class DbHelper { private static string dbProviderName = ...

  • .NET常用到的DbHelperSQL

    .NET常用到的DbHelperSQL_IT/计算机_专业资料。.NET常用到的DbHelperSQL 2011-03-02 11:30 /// ///执行一个不需要返回值的SqlCommand命令,通过指定专用的...

  • SqlDbHelper

    SqlDBHelper常用方法 5页 免费 喜欢此文档的还喜欢 SqlDbHelper 3页 免费 Sql...如存储过程或者SQL文本命令 /// <returns>返回查询结果集</returns> public Data...

  • DBHelper帮助类

    { public class DBHelper { //定义连接对象 private static SqlConnection _sCon... } /// /// 执行指定存储过程(事务中),返回结果集 /// /// 存储过程...

  • DBHelper类

    DBHelper类_计算机软件及应用_IT/计算机_专业资料。C#很好的数据库工具类...(E.Message); } } } /// /// 执行带一个存储过程参数的的SQL语句。...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email