Final Form of Parametric SQL Commands in ADO.NET

I am getting a syntax error when I submit a parameterized query to Access from my C # program via ADO.NET.

I certainly know which SQL line I have included in my code, with the parameter names embedded inside.

Does anyone know how I can look at the SQL string that is finally sent to the DBMS at the time of the call cmd.ExecuteNonQuery

?

Thanks.

EDIT:

Is there no way to see this line in the interactive debugger or in the access log or whatever? In order for anyone to reproduce my exact problem, they had to have my database, which will not. However, since interest has been expressed in the details of what I am trying to do, I post the following code snippet:

  OdbcCommand cmd = new OdbcCommand();
  cmd.CommandText = 
     @"insert into Posts (Page, Line, TimeStamp, Status) values
           (@pagename, @lineno, @now, 'SAVED')";
  cmd.Connection = _cn;
  cmd.Transaction = transaction;
  cmd.Parameters.Add(new OdbcParameter("@pagename",OdbcType.VarChar));
  cmd.Parameters.Add(new OdbcParameter("@lineno",OdbcType.VarChar));
  cmd.Parameters.Add(new OdbcParameter("@now",OdbcType.DateTime));
  cmd.Parameters["@pagename"].Value = pageId;
  cmd.Parameters["@lineno"].Value = lineId;
  cmd.Parameters["@now"].Value = now;
  cmd.ExecuteNonQuery();

      

Hope this helps.

Thanks again.

EDIT:

It seems to me that "TimeStamp" might be a reserved word in AccessSQL and that is probably the reason for the syntax error. However, even if we assume that this is the reason, the general question of how to see the SQL query in its final form remains open.

+2


a source to share


1 answer


Access only uses positional parameters.

All you have to do is change your SQL to this:

insert into Posts (Page, Line, [TimeStamp], Status) values ​​(?,?,?, 'SAVED')


make sure to add any additional parameters to the collection Parameters

in the correct order.

Edit: Updated to address the reserved word issue.

Edit: There is no way to trace the SQL that runs on an OLE DB connection, at least not currently. See this Microsoft KB article .

+1


a source







All Articles