M
M
Masalix2021-02-08 19:40:40
C++ / C#
Masalix, 2021-02-08 19:40:40

How to link access database to c# exe file?

Hello, such a problem, the exe file opens only when it is in the same place as the database file, but I need the exe file to open everywhere, even when the database is in a different place, how can this be done?
The code of the main form associated with the database was not done through the DataSet, as you can see.

string connectString =  "Provider=Microsoft.Ace.OleDB.12.0;Data Source=DB.mdb";
      private OleDbConnection myConnection;

        public Form1()
        {
            InitializeComponent();

           myConnection = new OleDbConnection(connectString);

           myConnection.Open();
           
        }


private void СохранитьToolStripMenuItem_Click(object sender, EventArgs e)
{
string zapros = "INSERT INTO table1 (результат) VALUES " + "('" + Convert.ToString(TextBox1.Text) + "')";
               OleDbCommand command = new OleDbCommand(zapros, myConnection);
                command.ExecuteNonQuery();
}

Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-02-08
@Masalix

Well, for example, do not hardcode the path, but put it in the configs / file open dialog

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question