Ticket Q249796
Visible to All Users

How do I write an SQL Statements for INSERT, UPDATE, & DELETE to multiple tables with only one query in an ASPxGridview

created 15 years ago

Hello,
I am trying to write an INSERT, UPDATE, and DELETE in the pop-up editor of an ASPxGridView, but everytime I try to enter multiple statements into the query box it says "SQL Syntax Errors Encountered: Unable to parse query text.
Can you please show me an example of how to write multiple table INSERT, UPDATE, and DELETE statements that will run in the Custom SQL statement query window of the smart tag for the ASPxGridView?
Please paste any examples into the body of your post, because due to network security issues where I work, I cannont open attachments.
Thanks,
Jonathan

Show previous comments (2)
DevExpress Support Team 15 years ago

    Hi Jonathan:

    1. Yes, you can leave the INSERT, UPDATE, and DELETE tabs of the smart tag. The RowUpdating, RowInserting and RowDeleting event handlers allow you to set the corresponding commands dynamically.
    2. By default, an editor is created for all visible fields in a data source, so there's no need to add additional code or markup. You can retrieve a value of this editor in the RowInserting and RowUpdating event handlers via the NewValues dictionary.
      For example, if a data source has a "ProductName" field, you can get the corresponding new value as follows:
    C#
    string newProduct = e.NewValues["ProductName"].ToString();

    If you use editors in template containers of the ASPxGridView and need to bind them to the datasource fields, you can use a binding expression. For example:
     <dxwgv:GridViewDataColumn FieldName="ProductName" VisibleIndex="8" Width="15%">
                     <DataItemTemplate>
                         <dxe:ASPxTextBox ID="templateBox" runat="server" Text='<%#Bind("ProductName")%>'>
                         </dxe:ASPxTextBox>
                     </DataItemTemplate>
                 </dxwgv:GridViewDataColumn>
    Thanks
    Kate.

    ?
    Unknown 15 years ago

      I'm trying to do what you suggested that I do, but when I click on the "New" button to Insert a new row, I get the following error:
      A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly. Pay attention to the character case.
      Ordinarily, I would put the primary key of the table I was reading from in the KeyFieldName with no problem, but since I am doing a multiple table join SELECT statement and there are no relationships among all the tables in my join, I have no real KeyFieldName. How do I handle this problem?
      Thanks,
      Jonathan

      DevExpress Support Team 15 years ago

        Hi Jonathan:
        I'm afraid, the ASPxGridView requires the KeyFieldName if you perform editing/inserting/deleting operations. This property isn't related to the real key field in a data source and you can set the FieldName of ANY existing data column of the grid as the KeyFieldName.
        The only requirement is that this field should contain unique values for each record.
        Thanks
        Kate.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.