如何连接内网 Access 上的数据库

发布于 2024-11-13 11:26:40 字数 1661 浏览 3 评论 0原文

我已经与 sql server 建立了连接,但我从未与 access 建立过连接,并且 现在这不在本地计算机中,如果不是,它将在服务器中 用户将用他们的信息填写表格,但数据库将在另一台计算机上,连接类别如何?我从来没有从事过access工作 如何进行添加、编辑、删除和查询?

在sql server中,这很容易

,这是我在sql中的类连接,我称它为form或另一个称为DAO的类,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace Proyecto1._0.Conexiones
{
    class Conexion
    {
        public SqlConnection conectar()
        {
            return new SqlConnection(@"data source=.; integrated security=true; initial catalog=dbmeridajoven;");
        }

        public bool ejecutarConsulta(string consulta)
        {
            try
            {
                SqlCommand comando = new SqlCommand(consulta, this.conectar());
                comando.Connection.Open();
                comando.ExecuteNonQuery();
                comando.Connection.Close();
                return true;
            }
            catch
            {
                MessageBox.Show("Consulta mal formada");
                return false;
            }
        }

        public DataTable regresarTabla(string consulta)
        {
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter(consulta, this.conectar());
                DataTable tabla = new DataTable("consulta");
                adapter.Fill(tabla);
                return tabla;
            }
            catch
            {
                MessageBox.Show("Consulta mal formada ");
                return new DataTable();
            }
        }
    }
}

我现在重复一遍,它具有访问权限,它用于内联网(在另一台计算机中是服务器)

I have made connection with sql server but i have never done a connection with access and
now this isn't in the computer local, if not it is going to be in a server
users are going to full the form with their information, but the database will be in another computer, how is the connection class to be? and I have never worked in access
how do i for Add, Edit, delete, and queries?

in sql server it was so easy

it was my class connection in sql and i call it since form or another class called DAO

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace Proyecto1._0.Conexiones
{
    class Conexion
    {
        public SqlConnection conectar()
        {
            return new SqlConnection(@"data source=.; integrated security=true; initial catalog=dbmeridajoven;");
        }

        public bool ejecutarConsulta(string consulta)
        {
            try
            {
                SqlCommand comando = new SqlCommand(consulta, this.conectar());
                comando.Connection.Open();
                comando.ExecuteNonQuery();
                comando.Connection.Close();
                return true;
            }
            catch
            {
                MessageBox.Show("Consulta mal formada");
                return false;
            }
        }

        public DataTable regresarTabla(string consulta)
        {
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter(consulta, this.conectar());
                DataTable tabla = new DataTable("consulta");
                adapter.Fill(tabla);
                return tabla;
            }
            catch
            {
                MessageBox.Show("Consulta mal formada ");
                return new DataTable();
            }
        }
    }
}

I repeat now is with access and it is for intranet (in another computer is the server)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-11-20 11:26:40

ConnectionStrings.com 是了解如何为各种数据库引擎创建连接字符串的绝佳资源。以下是 Access 连接字符串的一个示例:

提供商=Microsoft.Jet.OLEDB.4.0;数据源=C:\mydatabase.mdb;用户ID=admin;密码=;

生成连接字符串后,您会注意到文件路径包含在该字符串中;要在多个客户端之间共享数据库,您需要将数据库文件放在网络共享或驱动器上。例如,您的文件路径可能类似于“\\dbserver\databases\mydb.mdb”。

ConnectionStrings.com is a great resource for figuring out how to create a connection string for a variety of database engines. Here's one example of an Access connection string:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

Once you generate a connection string, you'll notice that the file path is included in the string; to share the database among mulitple clients, you'll need to put the database file on a network share or drive. For example, your file path could be something like "\\dbserver\databases\mydb.mdb."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文