1

Trying to do INSERT INTO into ACCESS database on Windows Form (C#), it doesn't give me any errors.

Connection Code:

public Connection()
    {
        string path = AppDomain.CurrentDomain.BaseDirectory;
        AppDomain.CurrentDomain.SetData("DataDirectory", path);
        string connString = "provider='Microsoft.jet.OleDb.4.0'; data source='|DataDirectory|\\App_Data\\maple_data.mdb'";
        this.con = new OleDbConnection(connString);
    }

The INSERT INTO code:

Connection c = new Connection();
                c.conOpen();
                OleDbCommand cm = new OleDbCommand();
                cm.Connection = c.Con;
                cm.CommandText = "INSERT INTO bot ([keystroke], [timer], [position]) VALUES (@key, @spamTime, 1)";
                cm.Parameters.AddWithValue("@key", Key.Text);
                cm.Parameters.AddWithValue("@spamTime", spamTime);
                cm.ExecuteNonQuery();
                c.conClose();
                MessageBox.Show("Key as been added.");

Thank you.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Naveh
  • 81
  • 9
  • `ExecuteNonQuery` is a function that returns the number if rows affected. If it is non zero, it likely means you are looking at the wrong DB given your connection string – Ňɏssa Pøngjǣrdenlarp Dec 06 '18 at 00:22
  • @WelcomeOverflow it does return 1, but how is it possible it will be a different DB? There is only one in the project folder, plus the only one with this name and table. – Naveh Dec 06 '18 at 00:27
  • 1
    @WelcomeOverflow you're right, I've understood that building a project makes another source of database (didn't know that), it does work there. Thank you for your assistance and guidance! – Naveh Dec 06 '18 at 00:37

0 Answers0