dynamic sql generation is not supported against multiple base tables

后端 未结 4 1661
死守一世寂寞
死守一世寂寞 2020-12-21 16:53

I tried to add a new row to a Table in an SQL DB, but I had a problem :

dynamic sql generation is not supported against multiple base tables

相关标签:
4条回答
  • 2020-12-21 17:25

    Add DISTINCT in your select statement with inner join.

    This will solve the issue.

    like Select Distinct Employee.Ecode, .........

    0 讨论(0)
  • 2020-12-21 17:30

    Change your select query and add distinct with inner join.

    For example there are two query from which you can understand that what I want to tell you

    Wrong query

    select iop.pob_id, iop.pob_product_id, iop.pob_qty, iop.pob_unit_id
        , iop.pob_rate, iop.pob_value, iop.pob_fiscalyear_id
        , **p.product_desc** as orderBy from inv_product_open_balc iop
    left join inv_product p on iop.pob_product_id = p.product_id
    where p.product_desc like 'Air Freshner%' and iop.pob_fiscalyear_id = 3
    

    Correct query

    select distinct iop.pob_id, iop.pob_product_id, iop.pob_qty
        , iop.pob_unit_id, iop.pob_rate, iop.pob_value, iop.pob_fiscalyear_id
        , **(select Product_desc from** inv_product p where p.product_id = iop.pob_product_id )as orderBy
    from inv_product_open_balc iop
    inner join inv_product p on iop.pob_product_id = p.product_id
    where p.product_desc like 'Air Freshner%' and iop.pob_fiscalyear_id = 3
    
    0 讨论(0)
  • 2020-12-21 17:43

    You can't use an SqlCommandBuilder here:

    Automatically generates single-table commands that are used to reconcile changes made to a DataSet with...

    The key words here being "single-table". It has no way to reverse engineer from the SELECT statement how a specific update should be applied (e.g. if you NULL all of the columns from the right side of a left join, should it delete the row, or set each column to null.

    You need to author appropriate Insert, Update and Delete commands on the SqlDataAdapter.

    0 讨论(0)
  • 2020-12-21 17:43

    With SqlCommandBuilder you can generate CRUD operation on entity

    Requirement of use is to define Select command before inserting , and include in the select command your primary Key.

    Link : http://msdn.microsoft.com/fr-fr/library/system.data.sqlclient.sqlcommandbuilder(v=vs.80).aspx

    MSDN Definition : Automatically generate Transact-SQL statements to update single table

    Nota : In your Update selectCommand, you defined left join query, and so you can create left join query, replace this query with just select.

    0 讨论(0)
提交回复
热议问题