using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class DbHelper
{
//连接数据库
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Staff_DB;Integrated Security=True");
/// <summary>
/// 执行查询语句,显示查询结果
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataTable GetTable(string sql)
{
SqlDataAdapter da = new SqlDataAdapter(sql,conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
/// <summary>
/// 执行增删改,返回影响行数
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public int GetAddDet(string sql)
{
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
int n = cmd.ExecuteNonQuery();
conn.Close();
return n;
}
}
}
DbHelper
最新推荐文章于 2022-05-30 22:31:09 发布