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;
}

}
}

posted on 2015-04-08 12:35  谢梦兮  阅读(158)  评论(0编辑  收藏  举报