开发者

How to connect with a database on Access inside a intranet

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)


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."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜