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>
/// sqloper 的摘要说明
/// </summary>
public class sqloper
{
    SqlConnection one = conn.sqlconn();
	public sqloper()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    /// <summary>
    ///执行一句sql语句
    /// </summary>
    //sql:数据库查询语句,conn:数据库连接
    public void dodata(string sql, SqlConnection conn)
    {
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
        }
        catch (System.Exception ee)
        {
            System.Web.HttpContext.Current.Response.Write(ee.Message.ToString());
        }
        finally
        {
            conn.Close();
        }
    }

    /// <summary>
    /// 阅读数据库的某个值
    /// </summary>
    public string loaddb(string sql, string val)
    {
        string temp = "";
        try
        {
            one.Open();
            SqlCommand cmd = new SqlCommand(sql, one);
            SqlDataReader rs = cmd.ExecuteReader();
            if (rs.Read())
            {
                temp = rs[val].ToString();
            }
            cmd.Dispose();
            rs.Dispose();
        }
        catch { }
        finally
        {
            one.Close();
        }
        return temp;
    }

    /// <summary>
    /// 建立数据库阅读对象
    /// </summary>
    public SqlDataReader readsql(string sql, SqlConnection conn)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = sql;
        cmd.Connection = conn;
        try
        {
            conn.Open();
        }
        catch { }
        SqlDataReader rs = cmd.ExecuteReader();
        
        return rs;
        cmd.Dispose();
        rs.Dispose();
        conn.Close();
        
    }
}
