c#数据库connection.Open()错误

本文关键字:错误 Open 数据库 connection | 更新日期: 2023-09-27 18:01:58

错误消息不断出来指向connection.open()在顶部,我无法解决它后不同的尝试方法imputing,有人吗?谢谢!

private void btnRegInfo_Click(object sender, EventArgs e)

     {
        OleDbConnection connect = new OleDbConnection();
        connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=:'Users'Student'Desktop'Database11.accdb";
        connect.Open();
    string Name = tbName.Text;
    OleDbCommand cmmd = new OleDbCommand("INSERT INTO table1(First Name)Values(@Name)", connect);
    if (connect.State == ConnectionState.Open)
    {
        cmmd.Parameters.Add("@Name", OleDbType.VarWChar, 20).Value = Name;
        try
        {
            cmmd.ExecuteNonQuery();
            MessageBox.Show("DATA ADDED");
            connect.Close();
        }
        catch (OleDbException expe)
        {
            MessageBox.Show(expe.Message);
            connect.Close();
        }
    }

    else
    {
        MessageBox.Show("CON FAILED");
    }


        if (tbName.Text != "Name" && tbPass.Text != "Password")
            {
                if (tbEmail.Text != "Email" && tbMobile.Text != "Number")
                {
                    if (tbFirstName.Text != "" && tbLastName.Text != "")
                    {
                        const int MIN_LENGTH = 8;
                        string password = tbPass.Text;
                        if (password.Length >= MIN_LENGTH && upperCase(password) >= 1)
                        {
                            r2.Text = "";
                            r2.ForeColor = Color.Red;
                        }
                        else
                        {
                            r2.Text = "*Password Is Bad*";
                            r2.ForeColor = Color.Red;

c#数据库connection.Open()错误

您的数据源显示如下:==>= 数据源:'用户桌面' '学生' Database11.accdb

我想知道你是否缺少驱动器号,如:==>数据源= c: ' '学生桌面' '用户Database11.accdb