c#database connection.Open()错误

时间:2016-08-12 01:33:41

标签: c# database

错误消息一直指向上面的connection.open(),并且我无法在不同的方法输入尝试后解决它,任何人?谢谢!

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;

1 个答案:

答案 0 :(得分:2)

您的数据来源显示以下内容:==> 数据源=:\ Users \ Student \ Desktop \ Database11.accdb

我想知道您是否错过了驱动器号,例如:==> 数据源= c:\ Users \ Student \ Desktop \ Database11.accdb