如何连接内网 Access 上的数据库
我已经与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ConnectionStrings.com 是了解如何为各种数据库引擎创建连接字符串的绝佳资源。以下是 Access 连接字符串的一个示例:
生成连接字符串后,您会注意到文件路径包含在该字符串中;要在多个客户端之间共享数据库,您需要将数据库文件放在网络共享或驱动器上。例如,您的文件路径可能类似于“\\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:
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."