using System;

using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace norke
{
	/// <summary>
	/// DBConn 的摘要说明。
	/// </summary>
	public class DBConn
	{
		private SqlConnection conn;

		public DBConn()
		{
			conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
			conn.Open();
		}

		public DBConn(string ConnStr)
		{
			conn=new SqlConnection(ConnStr);
			conn.Open();
		}

		public void Close()//关闭数据库连接
		{
			conn.Close();
			conn = null;
		}

		public SqlDataReader getDataReader(string SQLQuery)
		{
			SqlCommand cmd = new SqlCommand(SQLQuery,conn);
			return cmd.ExecuteReader();
		}

		public int Insert(string SQLQuery)
		{
			SqlCommand cmd = new SqlCommand(SQLQuery,conn);
			return cmd.ExecuteNonQuery();
		}


		public int Update(string SQLQuery)
		{
			SqlCommand cmd = new SqlCommand(SQLQuery,conn);
			return cmd.ExecuteNonQuery();
		}

		public int Delete(string SQLQuery)
		{
			SqlCommand cmd = new SqlCommand(SQLQuery,conn);
			return cmd.ExecuteNonQuery();
		}

		public DataSet getDataSet(string SQLQuery)
		{
			SqlDataAdapter da = new SqlDataAdapter(SQLQuery,conn);
			DataSet ds = new DataSet();
			da.Fill(ds);
			da.Dispose();
			da = null;
			return ds;
		}

		public ICollection CreateSource(string SQLQuery)
		{
			SqlDataAdapter da = new SqlDataAdapter(SQLQuery,conn);
			DataSet ds=new DataSet();
			da.Fill(ds,"mytable");
			return ds.Tables["mytable"].DefaultView;
		}




	}
}
