C# System.Data.OleDb.OleDbException';发生在System.Data.dll中
大家好,我是C#语言和Visual Studio平台的新手,最近我正在学习如何将access数据库与Visual Studio连接,并且第一次使用与数据库连接的相同代码,但经过一段时间后,当我再次编译时,标题中给出了错误。 为什么会这样C# System.Data.OleDb.OleDbException';发生在System.Data.dll中,c#,ms-access-2013,C#,Ms Access 2013,大家好,我是C#语言和Visual Studio平台的新手,最近我正在学习如何将access数据库与Visual Studio连接,并且第一次使用与数据库连接的相同代码,但经过一段时间后,当我再次编译时,标题中给出了错误。 为什么会这样 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.
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.Data.OleDb;
namespace Clinic_Management_System
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
try
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users
\Hassan Gillani\Documents\Clinic Management System.accdb; Persist Security Info = False; ";
connection.Open();
label1.Text = "Connected to Clinic Management System Database";
connection.Close();
}
catch (Exception exp)
{
MessageBox.Show("Error " + exp);
}
}
}
}
请访问我想查看的屏幕
使用逐字字符(@)并在中间分割你的路径不是一个好主意。 空格在路径中计数,因此用于连接的文件名为
C:\Users \Hassan Gillani\Documents\Clinic Management System.accdb;
如果您尝试在此字符串上使用File.Exists,则结果为false
不要在路径的中间分割你的连接字符串< /p>
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:\Users\Hassan Gillani\Documents\Clinic Management System.accdb;
Persist Security Info = False; ";
确保您的文件路径正确,例外情况是“无效文件名”是的,请检查是否不应转义文件路径,因为文件名中有空格我再次验证了路径是否正确我已通过右键单击文件和go属性指定了路径,然后是安全性,然后复制对象名字段中指定的整个路径