From子句ms访问中的语法错误

时间:2021-08-11 15:21:50

I am trying to query data from Ms access database with the following code.

我试图使用以下代码从Ms访问数据库查询数据。

string sql = @"INSERT INTO Mre_Pole (ElementID,GlobalID,UpdateState) values (:ElementID,:GlobalID,:UpdateState)";
string commandText2 = @"SELECT TOP 1 * FROM Mre_Pole ORDER BY objectid DESC";
command.CommandText = sql;
command.Parameters.AddWithValue(":ElementID", entityGuid.EntityId);
command.Parameters.AddWithValue(":GlobalID", entityGuid.Guid);
command.Parameters.AddWithValue(":UpdateState", UpdateState.Added);
command.ExecuteNonQuery();
command.Parameters.Clear();
command.CommandText = commandText2;

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);

but it throws an exception dataAdapter.Fill(ds);

但它抛出异常dataAdapter.Fill(ds);

Syntax Error in From clause

From子句中的语法错误

Anyone please help me with this problem.

有人请帮我解决这个问题。

1 个解决方案

#1


0  

Try

Change

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);

to

 OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandText2,"your oledbconnection");
    DataSet ds = new DataSet();
        dataAdapter.Fill(ds);

#1


0  

Try

Change

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);

to

 OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandText2,"your oledbconnection");
    DataSet ds = new DataSet();
        dataAdapter.Fill(ds);