Why doesn't calling my UPDATE query in an Access database via OleDb work?

Update 2: I solved it, see my answer.


I am calling queries in a Microsoft Access database from C # using OleDb, but I cannot get my update requests to work.

An error does not occur, but updates are not saved to the database.

Can anyone shed some light on this?


SQL query in the database:

UPDATE tableName SET tableName.LastPolledDtg = LastPolledDtg
WHERE tableName.key = ID;

FROM#

OleDbCommand command = new OleDbCommand();
SetCommandType(command, CommandType.StoredProcedure, "NameOfQueryInAccessDatabase");
AddParamToSQLCmd(command, "@ID", OleDbType.Integer, 4, ParameterDirection.Input, id);
AddParamToSQLCmd(command, "@LastPolledDtg", OleDbType.Date, 4, ParameterDirection.Input, DateTime.Now);
using (OleDbConnection connection = new OleDbConnection("connectionString"))
{
command.Connection = connection;
connection.Open();
result = command.ExecuteNonQuery();
}

Connection string:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Administrator\\Desktop\\dev\\src\\Website\\App_Data\\tracking.mdb"

Update 1:

I tried to narrow down the possibilities by creating a new database containing one table and one query, and access was closed when starting C # to update the table.

Updating is still not performed. I suspect this is a syntax problem (could there also be a problem with access rights?), But without error messages it’s pretty hard to debug them!

+3
4

- - , , .

:

UPDATE tableName SET tableName.LastPolledDtg = LastPolledDtg
WHERE tableName.key = ID;

UPDATE tableName SET tableName.LastPolledDtg = LastPolledDtgArg
WHERE tableName.key = ID; 

... # .

, : # , LastPolledDtg (1899 - ). OleDbCommand SQL .

, # :

OleDbCommand command = new OleDbCommand();
SetCommandType(command, CommandType.StoredProcedure, "NameOfQueryInAccessDatabase");
AddParamToSQLCmd(command, "@LastPolledDtgArg", OleDbType.Date, 4, ParameterDirection.Input, DateTime.Now);
AddParamToSQLCmd(command, "@ID", OleDbType.Integer, 4, ParameterDirection.Input, id);
using (OleDbConnection connection = new OleDbConnection("connectionString"))
{
command.Connection = connection;
connection.Open();
result = command.ExecuteNonQuery();
}

, .

+5

( LastPolledDtg ). , .

Access PARAMETER, :

PARAMETERS LastPolledDtgArg Text ( 255 ), ID Long;
UPDATE tableName SET tableName.LastPolledDtg = [LastPolledDtgArg]
WHERE tableName.key = [ID];

, SQL # , .

-

, , , LastPolledDtArg ID.

+3

ms-access , SQL.

+1

I am not an access encoder, but it seems like implicit transactions can be used. This would mean that when you execute the data modification command, the transaction automatically opens, which must be committed / rolled back explicitly in your code.

Either this, or for some reason, no lines will be affected by your update.

0
source

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


All Articles