dynamic sql generation is not supported against multiple base tables(多个基表不支持动态 sql 生成)
问题描述
我尝试向 SQL DB 中的表添加新行,但遇到了问题:
I tried to add a new row to a Table in an SQL DB, but I had a problem :
不支持对多个基表进行动态 sql 生成
dynamic sql generation is not supported against multiple base tables
这是我尝试过的代码:
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_");
}
推荐答案
更改您的选择查询并使用内部联接添加 distinct.
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
查询错误
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
正确查询
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
这篇关于多个基表不支持动态 sql 生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多个基表不支持动态 sql 生成
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01