INSERT OleDB C # Request

I know that it was 1,000,000,000 times, but not a single solution helped me. I want to insert data in C # using OleDB. I tried millions of solutions, but here is the simplest one that should work, but it is not:

 SQLCONNECTION = @"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=|DataDirectory|\dbScenariusz.mdb";

 using (OleDbConnection connection = new OleDbConnection(SQLCONNECTION))
            {
                string sql = "INSERT INTO Table (content) VALUES('lala')";
                connection.Open();
                OleDbCommand command = new OleDbCommand(sql, connection);
                command.ExecuteNonQuery();
                connection.Close();
            }

SQLCONNECTION is fine. It works fine for a SELECT query.

string sql - I tried this query in Access and it works fine.

I get no errors . He simply did not insert anything into the database. When I run a query in Access (in the same database), a row is inserted.

It is strange that command.ExecuteNonQuery (); returns 1! This means that 1 line is affected!

I really don't know where the problem is, so I really appreciate any help. Sorry for my English.

: . , ! wtf?:)

+3
3

DataDirectory. .mbd ? , ?

, .

+3

app.config. app.config, connectionString . . , connectionString :

connectionString = "Provider = Microsoft.ACE.OLEDB.12.0; = | DataDirectory |\App_Data\database.accdb; Persist Security Info = True"

, :

C:\Documents and Settings\Amuk\ \Visual Studio 2010\Projects\insertion\insertion\App_Data​​p >

connectionString

connectionString = "Provider = Microsoft.ACE.OLEDB.12.0; = C:\Documents and Settings\Amuk\ \Visual Studio 2010\Projects\insertion\insertion\App_Data\database.accdb; = True"

, , , , , connectionString, .

+2

You can try to use a transaction to commit changes.

command.Transaction = connection.BeginTransaction(); //after connection.open()

Then add

command.Transaction.Commit(); //Before connection.close()
0
source

Source: https://habr.com/ru/post/1793602/


All Articles