【发布时间】:2018-01-25 20:26:45
【问题描述】:
我正在尝试创建一个项目,该项目将读取、写入和检查我的访问数据库文件中的重复项。我正在使用 C# 并不断收到“如果连接状态 = 0,我已写入程序的连接失败错误。如果有人能提供任何帮助,我将不胜感激。我正在使用 Access 2016,但我不确定我需要哪些参考资料用于我的项目(如果有的话)。我在网上找到的所有东西要么已经过时,要么不起作用。
谢谢!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.IO;
using System.Data.OleDb;
namespace RHG
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.16.0;Data Source=C:\Users\grosales\Documents\rhg\RHG\Used.accdb"))
{
try
{
connection.Open();
MessageBox.Show("connected");
}
catch (Exception ex)
{
MessageBox.Show("connection failed");
}
}
}
`
【问题讨论】:
-
你在哪里打开你的连接?
-
你没有打开连接。
标签: c# .net ms-access-2016