动态SQL生成不支持针对多个基表 [英] dynamic sql generation is not supported against multiple base tables

查看:860
本文介绍了动态SQL生成不支持针对多个基表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个新行添加到表中的SQL数据库,但我有一个问题:

  

动态SQL生成不支持针对多个基表

这是在code我想:

 私人MyClass的MyClass的=新MyClass的();
私人SqlDataAdapter的适配器;
私人SqlDataAdapter的适配器2;

私人无效GestionCollections_Load(对象发件人,EventArgs的)
{
     适配器=新的SqlDataAdapter(选择Id_Collection ID,Libelle_Collection收集,Libelle_Editeur Editeur从Collection_左连接Editeur上Id_Editeur = Collection_.Id_Editeur_Editeur,myClass.cnx);
     adapter.Fill(myClass.dsCollection_);

     适配器2 =新的SqlDataAdapter(选择Id_Editeur ID,Libelle_Editeur Editeur从Editeur,myClass.cnx);
     adapter2.Fill(myClass.dsEditeur);
}

私人无效AjouterBarButton_ItemClick(对象发件人,DevEx press.XtraBars.ItemClickEventArgs E)
{
    字符串newKeyWordCollectionName = ajoutCollection.KeyWordCollectionName;
    字符串newKeyWordAEditeurName = ajoutCollection.KeyWordEditeurName;
    DataRow的行= myClass.ds.Tables [集_] NEWROW()。
    行[1] = newKeyWordCollectionName;

    的foreach(VAR myRow在myClass.ds.Tables [Editeur。AsEnumerable())
    {
         如果(newKeyWordAEditeurName == myRow [1]为String)
              行[2] =(int)的myRow [0];
    }
     myClass.ds.Tables [集_] Rows.Add(行)。
     SqlCommandBuilder建设者=新SqlCommandBuilder(适配器);
     adapter.Update(myClass.dsCollection_);

}
 

解决方案

您不能使用的 SqlCommandBuilder 这里:

  

自动生成用于协调对DataSet所作的同...修改的单表命令

中的关键词这里是单表。它没有办法扭转从 SELECT 语句怎么某个特定的更新应该应用工程师(例如,如果您 NULL 所有从右侧的左的列的加入,它应该删除的行,或设置每列设置为空。

您需要编写适当的插入,更新和对SqlDataAdapter的Delete命令。

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_");

}

解决方案

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.

这篇关于动态SQL生成不支持针对多个基表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆