DBHelp.cs
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:2k
源码类别:

SilverLight

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Data.SqlClient;
  11. /// <summary>
  12. /// DBHelp 的摘要说明
  13. /// </summary>
  14. public class DBHelp
  15. {
  16. public DBHelp()
  17. {
  18. //
  19. // TODO: 在此处添加构造函数逻辑
  20. //
  21. }
  22.     public static DataTable Select(string sql)
  23.     {
  24.         using (SqlConnection conn = new SqlConnection("server=.;database=mybookshop;uid=sa;pwd=sasa"))
  25.         {
  26.             using (SqlDataAdapter sdr = new SqlDataAdapter(sql, conn))
  27.             {
  28.                 using (DataSet ds = new DataSet())
  29.                 {
  30.                     sdr.Fill(ds);
  31.                     return ds.Tables[0];
  32.                 }
  33.             }
  34.         }
  35.     }
  36.     public static bool Update(string sql)
  37.     {
  38.         using (SqlConnection conn = new SqlConnection("server=.;database=mybookshop;uid=sa;pwd=sasa"))
  39.         {
  40.             using (SqlCommand com = new SqlCommand(sql, conn))
  41.             {
  42.                 try
  43.                 {
  44.                     conn.Open();
  45.                     int count = com.ExecuteNonQuery();
  46.                 if (count > 0)
  47.                 {
  48.                     return true;
  49.                 }
  50.                 else
  51.                 
  52.                     return false;
  53.                 }
  54.                 catch (Exception ex)
  55.                 {
  56.                     
  57.                     throw ex;
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     
  63. }