• 大小: 238KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: C#
  • 标签: C#源码  

资源简介

利用C#远程存取Access数据库

资源截图

代码片段和文件信息

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

namespace Remoteobject
{
    public class CRemoteAccess : MarshalByRefobject
    {
        public static string m_ConnString;
        private string m_sqlQuery;
        private OleDbConnection m_connection;
        private OleDbCommand m_command;
        private OleDbDataAdapter m_adapter;
        private OleDbCommandBuilder m_builder;
        private DataSet m_ds;
        private DataTable m_userTable;

        public CRemoteAccess()
{
}

        public void SetRemoteAccessConnString(string Connstr)
        {
            m_ConnString = Connstr;
        }

        public string GetRemoteAccessConnString()
        {
            return m_ConnString;
        }     

        private void SetDataobjects()
        {
            m_connection = new OleDbConnection(m_ConnString);
            m_command = new OleDbCommand(m_sqlQuery m_connection);
            m_adapter = new OleDbDataAdapter(m_command);
            m_builder = new OleDbCommandBuilder(m_adapter);
            m_ds = new DataSet(“MainDataSet“);
        }

        public bool TestConnectionIsOK(string connstr)
        {
            OleDbConnection testconn = null;
            try
            {
                testconn = new OleDbConnection(connstr);
                testconn.Open();
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                testconn.Close();
            }            
        }

        private void LoadData(string SqlStr string TableName)
        {
            try
            {
                if (m_userTable != null)
                {
                    m_userTable.Clear();
                }
                m_sqlQuery = SqlStr;// “select * from Test“;
                SetDataobjects();
                m_connection.Open();

                m_adapter.Fill(m_ds TableName);
                m_userTable = m_ds.Tables[TableName];
            }
            catch //(Exception ex)
            {

            }
            finally
            {
                m_connection.Close();
            }
        }

        public void SaveData(DataTable ClientDataTable)
        {
            try
            {
                m_connection.Open();
                m_adapter.Update(ClientDataTable);
            }
            catch //(Exception ex)
            {

            }
            finally
            {
                m_connection.Close();
            }
        }

        public DataTable GetUserTable(string SqlStr string TableName)
        {
            LoadData(SqlStr TableName);
            return m_userTable;
        }

    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     143360  2007-06-21 12:13  TestRemoteAccess\Demo\db.mdb

     文件      16384  2007-07-31 20:09  TestRemoteAccess\Demo\Remoteobject.dll

     文件      24576  2007-07-31 20:38  TestRemoteAccess\Demo\TestClient.exe

     文件      24576  2007-07-31 20:38  TestRemoteAccess\Demo\TestServer.exe

     文件       2873  2007-07-29 20:17  TestRemoteAccess\Remoteobject\CRemoteAccess.cs

     文件      16384  2007-07-31 20:32  TestRemoteAccess\Remoteobject\obj\Debug\Refactor\Remoteobject.dll

     文件      16384  2007-07-31 20:09  TestRemoteAccess\Remoteobject\obj\Debug\Remoteobject.dll

     文件      15872  2007-07-31 20:09  TestRemoteAccess\Remoteobject\obj\Debug\Remoteobject.pdb

     文件      16384  2007-07-28 17:22  TestRemoteAccess\Remoteobject\obj\Release\Remoteobject.dll

     文件      13824  2007-07-28 17:22  TestRemoteAccess\Remoteobject\obj\Release\Remoteobject.pdb

     文件        372  2007-07-31 20:38  TestRemoteAccess\Remoteobject\obj\Remoteobject.csproj.FileList.txt

     文件       1374  2007-07-28 17:05  TestRemoteAccess\Remoteobject\Properties\AssemblyInfo.cs

     文件       1967  2007-07-28 16:51  TestRemoteAccess\Remoteobject\Remoteobject.csproj

     文件       2232  2007-07-31 20:38  TestRemoteAccess\TestClient\frmTestClient.cs

     文件       7683  2007-07-31 20:32  TestRemoteAccess\TestClient\frmTestClient.Designer.cs

     文件       7742  2007-07-31 20:32  TestRemoteAccess\TestClient\frmTestClient.resx

     文件        908  2007-07-31 20:38  TestRemoteAccess\TestClient\obj\Debug\TestClient.csproj.GenerateResource.Cache

     文件      24576  2007-07-31 20:38  TestRemoteAccess\TestClient\obj\Debug\TestClient.exe

     文件        180  2007-07-31 20:38  TestRemoteAccess\TestClient\obj\Debug\TestClient.frmTestClient.resources

     文件      32256  2007-07-31 20:38  TestRemoteAccess\TestClient\obj\Debug\TestClient.pdb

     文件        180  2007-07-31 20:09  TestRemoteAccess\TestClient\obj\Debug\TestClient.Properties.Resources.resources

     文件        850  2007-07-28 17:22  TestRemoteAccess\TestClient\obj\Release\TestClient.csproj.GenerateResource.Cache

     文件      20480  2007-07-28 17:22  TestRemoteAccess\TestClient\obj\Release\TestClient.exe

     文件        180  2007-07-28 17:22  TestRemoteAccess\TestClient\obj\Release\TestClient.frmTestClient.resources

     文件      19968  2007-07-28 17:22  TestRemoteAccess\TestClient\obj\Release\TestClient.pdb

     文件        180  2007-07-28 17:22  TestRemoteAccess\TestClient\obj\Release\TestClient.Properties.Resources.resources

     文件        668  2007-07-31 20:38  TestRemoteAccess\TestClient\obj\TestClient.csproj.FileList.txt

     文件        477  2007-07-28 17:12  TestRemoteAccess\TestClient\Program.cs

     文件       1225  2007-07-28 17:05  TestRemoteAccess\TestClient\Properties\AssemblyInfo.cs

     文件       2875  2007-07-28 16:48  TestRemoteAccess\TestClient\Properties\Resources.Designer.cs

............此处省略113个文件信息

评论

共有 条评论