DBHelp.cs
资源名称:SunShine.rar [点击查看]
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:2k
源码类别:
SilverLight
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- /// <summary>
- /// DBHelp 的摘要说明
- /// </summary>
- public class DBHelp
- {
- public DBHelp()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- public static DataTable Select(string sql)
- {
- using (SqlConnection conn = new SqlConnection("server=.;database=mybookshop;uid=sa;pwd=sasa"))
- {
- using (SqlDataAdapter sdr = new SqlDataAdapter(sql, conn))
- {
- using (DataSet ds = new DataSet())
- {
- sdr.Fill(ds);
- return ds.Tables[0];
- }
- }
- }
- }
- public static bool Update(string sql)
- {
- using (SqlConnection conn = new SqlConnection("server=.;database=mybookshop;uid=sa;pwd=sasa"))
- {
- using (SqlCommand com = new SqlCommand(sql, conn))
- {
- try
- {
- conn.Open();
- int count = com.ExecuteNonQuery();
- if (count > 0)
- {
- return true;
- }
- else
- return false;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
- }