Hi All

I am trying to connect to access 07 via a windows app using msvs 05 in c#. I have the code which ive adapted from another working app but its now not working. Initialy the form should open an display the data rows in a table called events and then i want to add, change delete. For now i just wanna get it to connect and show the data. Unfortunately this causes an error saying

System.Data.OleDb.OleDbException was unhandled, Message="Not a valid file name."

I am new to c# an a little confused as to what i am doing wrong could someone point me in the right direction please!!
Apologies for the comments its helpin me rember what am doing while i learn lol

Heres the code ive bolded the error line

public partial class Form2 : Form
        public static string connectionString =
               "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
               + "data source = " + Application.StartupPath + //(Location) where to find db file in bin file

        //delcalring private variabe
        private OleDbDataAdapter dataAdapter;
        private DataSet dataSet;
        private DataTable dataTable;
        private OleDbConnection conn;

        //*** End ADO.Net objects ***

        // Database objects

        private static string EventName; //creates object in memory 1 instance used anytime
        private static string EventDate;

        public Form2()
            // Default select command on the Events table
            string commandstring = "select * from Events";//select everything from table

            // The link between the sql command and the database connection

            dataAdapter = new OleDbDataAdapter(commandstring, connectionString);//gives everythin from table to dataAdapter and use connection string

            //Define insert, update, and delete sql commands to use.

            //Declare and fill the in-memory dataset from the database
            dataSet = new DataSet();
            dataSet.CaseSensitive = true;
            [B]dataAdapter.Fill(dataSet, "Events");[/B]

            // Show all rows in the listbox
        private void Fill_1b()
            dataTable = dataSet.Tables["Events"];

            foreach (DataRow dataRow in dataTable.Rows)
                listBox1.Items.Add(EventName + "\t\t" + EventDate);
        } // *** Fill_1b ***

        private void LoadBuffers(DataRow prow)
            EventName = prow["EventName"].ToString().Trim();
            EventDate = prow["EventDate"].ToString().Trim();
        } //*** LoadBuffers ***

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

7 Years
Discussion Span
Last Post by carlakawill


The problem is with the connection string that you have provided.

Make the connection string to:

string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "" + Application.StartupPath + "\\Olympics.accdb";
OleDbConnection conn = new OleDbConnection(connectionString);

eliminate the "data source = " part from the connection string since you have already defined.

Good luck.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.