NEwbie Question: Getting DetailsView to output the Insert/UpdateCommandSQL to screen?

Discussion in 'ASP .Net' started by DC, Sep 12, 2007.

  1. DC

    DC Guest

    Ok so Im getting an

    " Syntax error in INSERT INTO statement.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: Syntax error in
    INSERT INTO statement."

    Question is how do I get the detailsview to output the actual SQL
    staemnet Im trying to execute to screen so I can debug my INSERT and
    UPDATE statements?

    Thanks in advance,
     
    DC, Sep 12, 2007
    #1
    1. Advertisements

  2. DC

    New Bee Guest

    you should put your failing code into a try/catch block and then examine the
    ex.message/stack trace. This may give you more information about why the
    code is failing.


    Try

    'Your Code

    Catch ex as exception

    response.write( ex.message )

    End Try
     
    New Bee, Sep 12, 2007
    #2
    1. Advertisements

  3. DC

    DC Guest

    Ok so if my AccessDataSource fro the details is as below I can change
    the InsertComand to

    InsertComand="Try

    INSERT INTO user_table (Image, ID, Title, ForeName, SurName,
    PhoneNo, RoomNo, EMail, Role, Course, Year, Staff, BscInfo, MscInfo,
    Mats, Cracks, HdrBoard, HdrForum, InfoSec, Lab, Media, PhdInfo,
    PhdSuper, Research, Secs, Security, Teapot, UgBoard, UgVis, WWW,
    StartDate, ProbabtionDate, EndDate, RetirementDate, FundingBody,
    ResearchGroup, LineManager, PayCategory, Notes) VALUES (@Image, @ID,
    @Title, @ForeName, @SurName, @PhoneNo, @RoomNo, @EMail, @Role, @Course,
    @Year, @Staff, @BscInfo, @MscInfo @Mats, @Cracks, @HdrBoard, @HdrForum,
    @InfoSec, @Lab, @Media, @PhdInfo, @PhdSuper, @Research, @Secs,
    @Security, @Teapot, @UgBoard, @UgVis, @WWW, @StartDate, @ProbabtionDate,
    @EndDate, @RetirementDate, @FundingBody, @ResearchGroup, @LineManager,
    @PayCategory, @Notes)

    Catch ex as exception

    response.write( ex.message )

    End Try
    "

    Or is this going to throw up an error?


    Here is the current AccessDataSource im using

    <asp:AccessDataSource id="DetailsSource" Runat="Server"
    DataFile="C:\Program Files\Common Files\ODBC\Data Sources\user_info2.mdb"

    SelectCommand="SELECT * FROM user_table WHERE ID = @ID"

    InsertCommand="INSERT INTO user_table (Image, ID, Title, ForeName,
    SurName, PhoneNo, RoomNo, EMail,
    Role, Course, Year, Staff, BscInfo, MscInfo, Mats,
    Cracks, HdrBoard, HdrForum, InfoSec, Lab,
    Media, PhdInfo, PhdSuper, Research, Secs, Security, Teapot, UgBoard,
    UgVis, WWW
    StartDate, ProbabtionDate, EndDate, RetirementDate, FundingBody,
    ResearchGroup, LineManager, PayCategory, Notes) VALUES (@Image, @ID,
    @Title, @ForeName, @SurName,
    @PhoneNo, @RoomNo, @EMail, @Role, @Course, @Year,
    @Staff, @BscInfo, @MscInfo
    @Mats, @Cracks, @HdrBoard, @HdrForum, @InfoSec, @Lab, @Media,
    @PhdInfo, @PhdSuper, @Research, @Secs, @Security, @Teapot, @UgBoard,
    @UgVis, @WWW, @StartDate, @ProbabtionDate, @EndDate, @RetirementDate,
    @FundingBody, @ResearchGroup, @LineManager, @PayCategory, @Notes)"

    UpdateCommand="UPDATE user_table SET [email protected], [email protected],
    [email protected], [email protected], [email protected],
    [email protected], [email protected], [email protected],
    [email protected], [email protected], [email protected], [email protected], [email protected],
    [email protected], [email protected], [email protected], [email protected],
    [email protected], [email protected],
    [email protected], [email protected], [email protected], [email protected],
    [email protected], [email protected],
    [email protected], [email protected], [email protected], [email protected],
    [email protected],
    [email protected], [email protected],
    [email protected], [email protected],
    [email protected],
    [email protected], [email protected],
    [email protected], [email protected] WHERE [email protected]"
     
    DC, Sep 12, 2007
    #3
  4. DC

    DC Guest

    Tried it and it gives an error like I expecetd

    Exception Details: System.Data.OleDb.OleDbException: Invalid SQL
    statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

    Where can I actually put the Try code? the DetailsView calls
    "Validate_Insert_Data" OnItemInserting, and "Display_Insert_Msg"
    OnItemInserted.

    Im guessing I need to put the try code into Validate_Insert_Data yes?

    <asp:DetailsView id="DetailsView" DataSourceID="DetailsSource"
    Runat="Server"
    AutoGenerateRows="False"
    DataKeyNames="ID"
    OnItemInserting="Validate_Insert_Data"
    OnItemInserted="Display_Insert_Msg"
    OnItemUpdating="Validate_Update_Data"
    OnItemUpdated="Display_Update_Msg"
    OnItemDeleting="Confirm_Delete"
    OnItemCommand="Get_Command"
    BorderStyle="Outset"
    BorderWidth="1"
    CellPadding="3"
    GridLines="None">
     
    DC, Sep 12, 2007
    #4
  5. DC

    bruce barker Guest

    currently this feature does not exist (does in the linq library in the
    next release). your best bet is to use sqlprofile a utility that comes
    with sqlserver.

    -- bruce (sqlwork.com)
     
    bruce barker, Sep 12, 2007
    #5
  6. DC

    DC Guest

    Im not using SQL Server, Im using an <asp:AccessDataSource to use an
    Access database.
     
    DC, Sep 12, 2007
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.