-1

enter image description here

There is an error within the database it keeps error.

provider is not regsitered to the local machine

Idk why, i'm new to c# so i a little bit confuse to the database system. Here is what i've coded:

string randomcode;
private static string to;

        public Form1()
        {
            var connstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=//Database/DB.accdb;Jet OLEDB:Database Password=xxxxxxxx;";
            var query = "INSERT INTO Random(Generate, Number) VALUES(@Generate, @Number)";
            var conn = new OleDbConnection(connstr);
            var cmd = new OleDbCommand(query, conn);
            try
            {
                conn.Open();
                cmd.Parameters.Add("@Generate", OleDbType.Integer).Value = randomcode;
                cmd.ExecuteNonQuery();
                MessageBox.Show("Connected");
                conn.Close();
            }
            catch
            {
                MessageBox.Show("err");
            }
        }

1 Answers1

0

Check your connection string. Make sure that you have access to the location the DB is stored.

If you're trying to use a network location, you're missing the share and your slashes are the wrong way.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\server\share\folder\myAccessFile.accdb;

If you're trying to hit a data directory you would do it like this.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\myAccessFile.accdb;Persist Security Info=False;
Rob Stewart
  • 441
  • 4
  • 14