Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

c# - dynamic sql generation is not supported against multiple base tables

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

this is the code I tried :

private MyClass myClass = new MyClass();
private SqlDataAdapter adapter;
private SqlDataAdapter adapter2;

private void GestionCollections_Load(object sender, EventArgs e)
{
     adapter = new SqlDataAdapter("select Id_Collection ID, Libelle_Collection Collection,Libelle_Editeur Editeur from Collection_ left join Editeur on Id_Editeur = Collection_.Id_Editeur_Editeur", myClass.cnx);
     adapter.Fill(myClass.ds, "Collection_");

     adapter2 = new SqlDataAdapter("Select Id_Editeur ID,Libelle_Editeur Editeur from Editeur", myClass.cnx);
     adapter2.Fill(myClass.ds, "Editeur");
}

private void AjouterBarButton_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    String newKeyWordCollectionName = ajoutCollection.KeyWordCollectionName;
    String newKeyWordAEditeurName = ajoutCollection.KeyWordEditeurName;        
    DataRow row = myClass.ds.Tables["Collection_"].NewRow();
    row[1] = newKeyWordCollectionName;

    foreach(var myRow in myClass.ds.Tables["Editeur"].AsEnumerable())
    {
         if (newKeyWordAEditeurName == myRow[1] as String)
              row[2] = (int)myRow[0];
    }
     myClass.ds.Tables["Collection_"].Rows.Add(row);
     SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
     adapter.Update(myClass.ds, "Collection_");

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...