0

I want to display the route names inside in my combo box from a local access database but I get this error and I don't know why. I tried a lot of stuff that I found online but none of them helped.

Maybe there is something wrong with the code?

        private void Form1_Load(object sender, EventArgs e)
    {
        OleDbConnection connection = new OleDbConnection();
        //Connection string:
        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=‪E:\Programming\Job\Jaratok.accdb;Persist Security Info=False;";

            connection.Open();

            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
            string query = "SELECT Name FROM Route";
            command.CommandText = query;

            OleDbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                comboBox1.Items.Add(reader["Name"].ToString());
            }

            connection.Close(); 

enter image description here

So as you can see, the database is there, in the folder but still... enter image description here

jps
  • 20,041
  • 15
  • 75
  • 79
J3htro
  • 260
  • 1
  • 3
  • 12
  • 1
    Presuming `File.Exists(@"‪E:\Programming\Job\Jaratok.accdb")` is true, have you tested compiling specifically to 32 or 64-bit? – Zer0 Sep 11 '20 at 00:53
  • Please open a command prompt, go to E:\Programming\Job\ and type in `dir`. Then show a screenshot of that (such that we can see the folder name and the file name in the screenshot). – mjwills Sep 11 '20 at 01:03
  • Not sure if it works. Try to change the platform target to `x86`. – 大陸北方網友 Sep 11 '20 at 01:35
  • Does this answer your question? [Error: Not a valid file name ( OleDbException )](https://stackoverflow.com/questions/25114598/error-not-a-valid-file-name-oledbexception) – vanisk Sep 11 '20 at 06:51
  • @Zer0 Somewhy File.Exists(@"‪E:\Programming\Job\Jaratok.accdb") returns false but the file is in that folder. – J3htro Sep 11 '20 at 07:35

1 Answers1

0
=‪E:\Programming\Job\Jaratok.accdb

There is a hidden character after the = and before the E:. You can spot it by putting your cursor to the left of the =. Now press right arrow. It moves. Now press it again. It doesn't move.

As such, you need to remove that hidden character (i.e. delete the = and E then add them back in).

mjwills
  • 23,389
  • 6
  • 40
  • 63