在网上搜索了C#的案例,但都是与SQL相连的案例,作为初学者,学习了ACCESS 与C# 我想找些两者合作之案例,不知有哪能位高人能指点一二啊???!!!

解决方案 »

  1.   

    用MSSQL是一样的,如果不涉及复杂的操作的话!
      

  2.   

    谢谢!! 但关键是要求是ACCESS 唉!!
      

  3.   

    网上应该有啊,CSDN下载就应该有,ACCESS和SQL SERVER的,用工厂模式的
      

  4.   

    C#的我不知道,有VB.NET的http://bingning.net/VB/SOURCE/database/access.html自定义类,参考一下。
      

  5.   

    和控制SQL一样,只是SQLConnection,SQLCommand等换成OleDBConnection,OleDBCommand
    连接字符串要不会写的话你先手动绑定一个,看一下自动生成的字符串就OK了。
    一切都和SQL一样用。
      

  6.   

    http://www.51aspx.com/CV/XmxCms/  这个程序是用Access做的!
      

  7.   

      /// <summary>
            /// 用DataSet来读取数据
            /// </summary>
            static void DataSetRwadData()
            {
                /****************************************************************************
                * 用DataSet来读取数据
                ****************************************************************************/
                //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>            Console.WriteLine("用DataSet来读取数据");            //创建Connection对象            
               OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\XXX.mdb");
                //打开连接
                conn.Open();            //sql语句
                string strSQL = "select * from tablename";            //创建DbDataAdapter对象
                OleDbDataAdapter ap = new OleDbDataAdapter(strSQL, conn);            //创建DataSet 对象
                DataSet ds = new DataSet();            //利用DbDataAdapter里面的Fill方法填充DataSet对象
                ap.Fill(ds);            //创建DataTable 对象
                DataTable dt = ds.Tables[0];            //显示数据
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Console.WriteLine(dt.Rows[i]["字段名"] + "\t" + dt.Rows[i]["字段名"]);
                }            //关闭连接
                conn.Close();            //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<        }
      

  8.   

    链接ACCESS的通用类
    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.OleDb;/// <summary>
    /// DataAccess 的摘要说明
    /// </summary>
    public class DataAccess
    {
        protected static OleDbConnection conn = new OleDbConnection();
        protected static OleDbCommand comm = new OleDbCommand();
     public DataAccess()
     {
      //init
     }
        private static void openConnection()
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source="+ConfigurationManager.AppSettings["myconn"];//web.config文件里设定。
                comm.Connection = conn;
                try
                {
                    conn.Open();
                }
                catch (Exception e)
                { throw new Exception(e.Message); }        }
           
        }//打开数据库
      
        private static void closeConnection()
        {
            if (conn.State == ConnectionState.Open)
            { 
                conn.Close();
                conn.Dispose();
                comm.Dispose();
            }
        }//关闭数据库    public static void excuteSql(string sqlstr)
        {
            try
            {
                openConnection();
                comm.CommandType = CommandType.Text;
                comm.CommandText = sqlstr;
                comm.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            { closeConnection(); }
        }//执行sql语句    public static OleDbDataReader dataReader(string sqlstr)
        {
            OleDbDataReader dr = null;
            try
            {
                openConnection();
                comm.CommandText = sqlstr;
                comm.CommandType = CommandType.Text;            dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch
            {
                try
                {
                    dr.Close();
                    closeConnection();
                }
                catch { }
            }
                return dr;
            }//返回指定sql语句的OleDbDataReader对象,使用时请注意关闭这个对象。
        public static void dataReader(string sqlstr, ref OleDbDataReader dr)
        {
            try
            {
                openConnection();
                comm.CommandText = sqlstr;
                comm.CommandType = CommandType.Text;
                dr=comm.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch
            {
                try
                {
                    if (dr != null && !dr.IsClosed)
                        dr.Close();
                }
                catch
                {
                }
                finally
                {
                    closeConnection();
                }
            }
        }//返回指定sql语句的OleDbDataReader对象,使用时请注意关闭    public static DataSet dataSet(string sqlstr)
        {
            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter();
            try
            {
                openConnection();
                comm.CommandType = CommandType.Text;
                comm.CommandText = sqlstr;
                da.SelectCommand = comm;
                da.Fill(ds);
     
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                closeConnection();
            }
            return ds;
        }//返回指定sql语句的dataset    public static void dataSet(string sqlstr, ref DataSet ds)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            try
            {
                openConnection();
                comm.CommandType = CommandType.Text;
                comm.CommandText = sqlstr;
                da.SelectCommand = comm;
                da.Fill(ds);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                closeConnection();
            }
        }//返回指定sql语句的dataset    public static DataTable dataTable(string sqlstr)
        {
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter();
            try
            {
                openConnection();
                comm.CommandType = CommandType.Text;
                comm.CommandText = sqlstr;
                da.SelectCommand = comm;
                da.Fill(dt);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                closeConnection();
            }
            return dt;
        }//返回指定sql语句的datatable
        public static void dataTable(string sqlstr, ref DataTable dt)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            try
            {
                openConnection();
                comm.CommandType = CommandType.Text;
                comm.CommandText = sqlstr;
                da.SelectCommand = comm;
                da.Fill(dt);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                closeConnection();
            }
        }//返回指定sql语句的datatable    public static DataView dataView(string sqlstr)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            DataView dv = new DataView();
            DataSet ds = new DataSet();
            try
            {
                openConnection();
                comm.CommandType = CommandType.Text;
                comm.CommandText = sqlstr;
                da.SelectCommand = comm;
                da.Fill(ds);
                dv = ds.Tables[0].DefaultView;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                closeConnection();
            }
            return dv;
        }
    //返回指定sql语句的dataview}