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

DBHelper.cs

sql数据库C#公共类

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



namespace JXCDAL
{
public static class DBHelper
{
private static SqlConnection connection;
public static SqlConnection Connection
{
get
{
string connectionString = "server=.\\SQLEXPRESS;database=JXC;uid=sa;Password=123";
if (connection == null)
{
connection = new SqlConnection(connectionString);
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
}

public static int ExecuteCommand(params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = Connection;
cmd.CommandText = "Pro_UpdateBooksCatagory";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(values);
int result = cmd.ExecuteNonQuery();
return result;
}

public static int ExecuteCommand(string safeSql)
{
SqlCommand cmd = new SqlCommand(safeSql, Connection);
int result = cmd.ExecuteNonQuery();
return result;
}

public static int ExecuteCommand(string sql, params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand(sql, Connection);
cmd.Parameters.AddRange(values);
return cmd.ExecuteNonQuery();
}

public static int GetScalar(string safeSql)
{
SqlCommand cmd = new SqlCommand(safeSql, Connection);
int result = Convert.ToInt32(cmd.ExecuteScalar());
return result;
}

public static int GetScalar(params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = Connection;
cmd.CommandText = "Pro_InsertOrder";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(values);
int result = Convert.ToInt32(cmd.ExecuteScalar());
return result;
}

public static int GetScalar(string sql, params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand(sql, Connection);
cmd.Parameters.AddRange(values);
int result = Convert.ToInt32(cmd.ExecuteScalar());
return result;
}

public static SqlDataReader GetReader(string safeSql)

第1页

你可能喜欢

热门文档

相关文档

  • DbHelperSQL.cs

    ?Title: DbHelperSQL.cs From目田文摘 Time:Tue, 18 Nov 2008 14:22:27 +...SQLHelper.cs经典代码 7页 1下载券 SqlHelper详解 21页 免费 微软DBHelper类 ...

  • DbHelperSQL.cs

    } #endregion /// /// 另一版本的DbHelper /// /// /// <returns></returns> #region public static int ExecuteCommand(string safeSql) // sql...

  • DbHelperSQL.cs

    DbHelperSQL.cs_计算机软件及应用_IT/计算机_专业资料。浩方DBHelperusing System; using System.Collections; using System.Collections.Generic; using System.Collection...

  • net链接数据库的dbHelper类

    net链接数据库的dbHelper类_IT/计算机_专业资料。.net连接数据库的DBhepler类 下载下来,把后缀名直接改为dbHelper.cs就可以用了。 在webConfig里面配置连接,把名称...

  • SqlDBHelper常用方法

    SqlDBHelper常用方法_IT/计算机_专业资料。SqlDBHelper常用方法/*=== * .net 连接数据库常用方法 * Author : dongny,Li * E-mail : xing.dong.li@163.com ...

  • DBHelper类

    DBHelper类_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 DBHelper类_计算机软件及应用_IT/计算机_专业资料。DBHelper类...

  • 关于dbhelper详解

    关于dbhelper详解_IT/计算机_专业资料。关于dbhelper详解namespace Mode.DAL //命名空间 { public static class DBHelper { private static SqlConnection connection; ...

  • DBHelper类说明文档

    DBHelper类说明文档_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 DBHelper类说明文档_IT/计算机_专业资料。今日推荐 89份文档 ...

  • DBHelper

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

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