Any way to see SQL prior to execute?

Anyone know of a way to debug or view or print the SQL just before it executes by the tableadapter.   I have a simple update, works fine if I manually run it in Access.  But same data throws datatype mismatch exception during an insert using VCSE.

 

Thanks.

JS




Answer this question

Any way to see SQL prior to execute?

  • Tobin Titus

    Hi,

    You can place a break on your tableadapter.Update Statement. And add a Watch, using tableadapter.InsertCommand.CommandText to be able to see the value. Or if you want the already parsed Sql String, thenits proper to use the sqlProfiler, its a tool readily available in Sql2000. It traps all sql statements being issued in your Database.

     

    cheers,

    Paul June A. Domag



  • CommonCents

    Paul-

    Once again, your pointers much appreciated.

    JS



  • Vermeulen

    Thanks Paul-

    I'll review what I did for anyone else who is interested.

    I put a breakpoint at that line.  Then I added tblAdapter to the watch.   That is, i highlighted tblAdapter, and then rt-mouse click and selected 'Add Watch' and it was in the watch area. 

    Next I  opened that watch item and found '_adapter' and then under that found the InsertCommand, DeleteCommand, ..etc.

    Then under the InsertCommand, I found 'Parameters->Base->Base->Non-Public Members->_items and found each parameter which would be replaced in the InsertCommand.

     Thanks.

    JS



  • MVerdeur

    Hi,

    You can place a Break on the line that calls the update statement:

    tblAdapter.Update(dsRef.History);

    You can then place this on your watch to see the the value of your Insert statement:

    tblAdapter.InsertCommand.CommandText

    cheers,

    Paul June A. Domag



  • GvanderMerwe

    Hi Paul-

    Thanks for the idea, however, I've been unable to find that exact location to put a watch.

    If you are still monitoring this thread, would you mind giving me some ideas.

    Thanks.
    JS

    ----------------------------------------------------------------------------------

    My code:

    Calling Code

    ... DataRow myNewRow = buildRecordFromScreenData();

    if (myNewRow != null){

    dsRef.Tables["History"].Rows.Add(myNewRow);

    tblAdapter.Update(dsRef.History);

    }

    ---------------------------------------------------

    AppDataSet.Designer.cs

    public partial class HistoryTableAdapter : System.ComponentModel.Component {
    private System.Data.OleDb.OleDbDataAdapter _adapter;
    private System.Data.OleDb.OleDbConnection _connection;
    private System.Data.OleDb.OleDbCommand[] _commandCollection;
    ...

    this._connection = value;
    if ((this.Adapter.InsertCommand != null)) {
    this.Adapter.InsertCommand.Connection = value;
    }
    ...

    private void InitAdapter() {
    this._adapter = new System.Data.OleDb.OleDbDataAdapter();

    ...

    this._adapter.InsertCommand = new System.Data.OleDb.OleDbCommand();
    this._adapter.InsertCommand.Connection = this.Connection;
    this._adapter.InsertCommand.CommandText = @"INSERT INTO `History` (`HistRef`,

    ...

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public virtual int Insert(
    string p1,
    string p2,
    ...

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, false)]
    public virtual int InsertQuery(
    string HistRef, ...



  • Any way to see SQL prior to execute?