首页 > 数据库技术 > 详细

我的DBHelper类

时间:2015-04-08 14:40:06      阅读:245      评论:0      收藏:0      [点我收藏+]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;


namespace DAL
{
public class DBHelper
{
//创建链接字符串
public static string sqlconn = "Data Source=.;Initial Catalog=StudentDB;Integrated Security=True";
//创建链接对象
public static SqlConnection conn = new SqlConnection(sqlconn);

//增删改方法
public static bool ExeQuteNonQuery(string sql)
{
//打开链接对象
conn.Open();
//创建命令对象
SqlCommand cmd = new SqlCommand(sql,conn);
//执行命令对象
int result = cmd.ExecuteNonQuery();
conn.Close();
if (result > 0)
{
return true;
}
else {
return false;
}
}
//查询方法
public DataTable ExeQuteTable(string sql)
{
//创建数据适配器
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataTable table=new DataTable ();
da.Fill(table);
return table;
}

}
}

我的DBHelper类

原文:http://www.cnblogs.com/xiemengxi-123/p/4402073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!