using System;
using System.Data;
using System.Data.SqlClient;
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;

/// <summary>
/// DataOperate 的摘要说明
/// </summary>
public class DataOperate
{
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
	public DataOperate()
	{
	}
    public bool DataCom(string sqlstr)
    {
        sqlcon.Open();
        SqlCommand sqlcomm = new SqlCommand(sqlstr, sqlcon);
        try
        {
            sqlcomm.ExecuteNonQuery();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            sqlcon.Close();
        }
    }
    public bool gvBind(GridView gv, string sqlstr)
    {
        sqlcon.Open();
        SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet mydataset = new DataSet();
        sqldataadapter.Fill(mydataset);
        gv.DataSource = mydataset;
        try
        {
            gv.DataBind();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            sqlcon.Close();
        }
    }
    public bool dataBind(DataList dl,string sqlstr)
    {
        sqlcon.Open();
        SqlDataAdapter myadapter = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet mydataset = new DataSet();
        myadapter.Fill(mydataset);
        dl.DataSource = mydataset;
        try
        {
            dl.DataBind();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            sqlcon.Close();
        }
    }
}
