Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.SqlClient;
- using System.Data;
- namespace QuanLiBanHang
- {
- class XulyDulieu
- {
- SqlConnection con;
- public XulyDulieu()
- {
- this.con = new SqlConnection();
- this.con.ConnectionString= @"Data Source=PHONGVU\SQLEXPRESS;Initial Catalog=QLBH_CS414;Integrated Security=True";
- }
- public void Moketnoi()
- {
- if (con.State == System.Data.ConnectionState.Closed)
- con.Open();
- }
- public void Dongketnoi()
- {
- if (con.State == System.Data.ConnectionState.Open)
- con.Close();
- }
- /// <summary>
- /// Thực thi sql(select*from)
- /// Trả về kiểu dl bảng DataTable
- /// </summary>
- /// <param name="sql">sql=select*from...</param>
- /// <returns></returns>
- public DataTable table(string sql)
- {
- this.Moketnoi();
- DataTable tb = new DataTable();
- SqlDataAdapter adp = new SqlDataAdapter(sql, con);
- adp.Fill(tb);
- this.Dongketnoi();
- return tb;
- }
- /// <summary>
- /// Thực thi sql(insert into,delete,update)
- /// Trả về hai giá trị (0 và <>0)
- /// nếu=0 thành công
- /// nếu <> không thành công
- /// </summary>
- /// <param name="sql"></param>
- /// <returns></returns>
- public int ThucthiSql(string sql)
- {
- int result = 0;
- this.Moketnoi();
- SqlCommand cmd = new SqlCommand(sql,con);
- result = (int)cmd.ExecuteNonQuery();
- this.Dongketnoi();
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement