using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace 小型宾馆管理系统
{
    public class database
    {
       
        public OleDbConnection dataConnection = new OleDbConnection();
        public OleDbDataAdapter dataadapter = new OleDbDataAdapter();
        public DataSet dataset = new DataSet();
        public OleDbCommand command = new OleDbCommand();

        //定义连接字符串
        string connstr = @"Provider = Microsoft.Jet.OLEDB.4.0;" + @"Data Source =.\hotelmanagement.mdb";
        public DataSet GetDataFromDB(string sqlStr)
        {
            try
            {
                dataConnection.ConnectionString = connstr;
                dataadapter = new OleDbDataAdapter(sqlStr, dataConnection);
                dataset.Clear();
                dataadapter.Fill(dataset);
                dataConnection.Close();

                
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                dataConnection.Close();
            }
           
                return dataset;
            　
               
        }
        public bool UpdataDB(string sqlStr)
        {
            try
            {
                dataConnection.ConnectionString = connstr;
                dataConnection.Open();
                command = dataConnection.CreateCommand();
                command.CommandText = sqlStr;
                command.ExecuteNonQuery();
                dataConnection.Close();
                return true;

            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
                dataConnection.Close();
                return false;
            }
        }
        
    }
}
