DBHelper.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. namespace DAL
  8. {
  9. public class DBHelper
  10. {
  11. //public static SqlConnection sqlconn;
  12. //public static void conn() {
  13. private static string str = "server=.;integrated security= true;database=HotelManage";
  14. //sqlconn = new SqlConnection(sql);
  15. //sqlconn.Open();
  16. //}
  17. public static DataTable Query(string sql) {
  18. SqlConnection conn = new SqlConnection(str);
  19. SqlCommand comm = new SqlCommand(sql, conn);
  20. SqlDataAdapter da = new SqlDataAdapter(comm);
  21. DataTable dt = new DataTable();
  22. da.Fill(dt);
  23. conn.Close();
  24. return dt;
  25. }
  26. public static int Modify(string sql) {
  27. SqlConnection conn = new SqlConnection(str);
  28. conn.Open();
  29. SqlCommand comm = new SqlCommand(sql, conn);
  30. int res = comm.ExecuteNonQuery();
  31. conn.Close();
  32. return res;
  33. }
  34. }
  35. }