Small is New Big in C#

Coding

Access Class

leave a comment »

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

namespace Access
{
    class Access
    {
        private OleDbConnection conn;
        private string connstring;

        public Access(string DBPath)
        {
            connstring = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source="; //Microsoft.ACE.OLEDB.12.0  Microsoft.Jet.OleDb.4.0 does not support Access 2007
            connstring += DBPath;
            conn = new OleDbConnection(connstring);
            conn.Open();
        }

        public OleDbConnection DBConn()
        {
            conn.Open();
            return conn;
        }

        public void Close()
        {
            conn.Close();
        }

        public DataTable SelectToDataTable(string sqlcomm)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
         
        }

        public DataSet SelectToDataSet(string sqlcomm, string tableName)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            DataSet ds = new DataSet();
            ds.Tables.Add(tableName);
            adapter.Fill(ds, tableName);
            return ds;
        }

        public DataSet SelectToDataSet(string sqlcomm, string tableName, DataSet dsName)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            ds = dsName;
            adapter.Fill(dsName, tableName);
            return ds;
        }

        public OleDbDataAdapter SelectToOleDbDataAdapter(string sqlcomm)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            return adapter;
        }

        public bool ExecuteSQLNonquery(string sqlcomm)
        {
            OleDbCommand cmd = new OleDbCommand(sqlcomm, conn);
            try
            {
                cmd.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

Advertisements

Written by nauhil

July 17, 2010 at 10:28 pm

Posted in Levels Of Details

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: