ado.net两个表更新数据

return false 2017-11-28 05:53:09
rt,
有一个界面,数据从mssql a表和b表过来
现在要更新界面中的所有数据,我是这么写的

string update = "update ems_xp set a.property_num='" + this.资产.Value + "',a.Section_num='" + this.部门管理编号.Value + "',a.sn='" + this.序列号.Value + "',b.ip='" + this.IP地址.Value + "',b.mac='" + this.MAC.Value + "',b.hostname='" + this.电脑名.Value + "',a.model='" + this.型号.Value + "',a.type_s='" + this.类型.Value + "',a.Supplier='" + this.品牌.Value + "',a.cpu='" + this.CPU.Value + "',a.hdd='" + this.硬盘.Value + "',a.memory='" + this.内存.Value + "',a.statuss='" + this.资产状态.Value + "',a.takes='" + this.使用担当.Value + "',a.contact='" + this.联络员.Value + "',a.Acquire_date='" + this.取得日期.Value + "',a.update_time='" + this.更新日期.Value + "',a.position='" + this.位置.Value + "',a.is_null='" + this.资产有无.Value + "',a.is_num='" + this.有无标签.Value + "',b.floor='" + this.楼层.Value + "' from ems_xp as a inner join macip as b on a.property_num=b.bh";
SqlCommand cmd=new SqlCommand(update,strcon);
cmd.ExecuteNonQuery();

结果报错:无法绑定由多个部分组成的标识符 "a.property_num"。
我这样写好像也只能更新a表的数据

请问各位大侠有什么方法么?
...全文
290 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
l35740623 2017-12-06
  • 打赏
  • 举报
回复
把值传入存储过程来处理。 但是,我觉得用事务会更好
lkf181 2017-12-01
  • 打赏
  • 举报
回复
执行两次更新把,分别更新两张表..........
Hello World, 2017-12-01
  • 打赏
  • 举报
回复
每条语句只能更新一个表,第两条语句更新,事务处理 update a set a.xx=xxxx from table1 a inner table2 b on a.id=b.xxx where xxxx update b set b.xx=xxxx from table1 a inner table2 b on a.id=b.xxx where ccc 另外,最好用参数化查询,不要拼字符串
  • 打赏
  • 举报
回复
如果 ems_xp  中包含 property_num 那么 1L 的写法其实就可以了,没必须一定加a ,你说不行,估计你要表达的意思都没说清楚
  • 打赏
  • 举报
回复
引用 楼主 qq_23934571 的回复:
rt, 有一个界面,数据从mssql a表和b表过来 现在要更新界面中的所有数据,我是这么写的

string update = "update  ems_xp set a.property_num='" + this.资产.Value + "',a.Section_num='" + this.部门管理编号.Value + "',a.sn='" + this.序列号.Value + "',b.ip='" + this.IP地址.Value + "',b.mac='" + this.MAC.Value + "',b.hostname='" + this.电脑名.Value + "',a.model='" + this.型号.Value + "',a.type_s='" + this.类型.Value + "',a.Supplier='" + this.品牌.Value + "',a.cpu='" + this.CPU.Value + "',a.hdd='" + this.硬盘.Value + "',a.memory='" + this.内存.Value + "',a.statuss='" + this.资产状态.Value + "',a.takes='" + this.使用担当.Value + "',a.contact='" + this.联络员.Value + "',a.Acquire_date='" + this.取得日期.Value + "',a.update_time='" + this.更新日期.Value + "',a.position='" + this.位置.Value + "',a.is_null='" + this.资产有无.Value + "',a.is_num='" + this.有无标签.Value + "',b.floor='" + this.楼层.Value + "' from  ems_xp as a inner join macip as b on a.property_num=b.bh";
        SqlCommand cmd=new SqlCommand(update,strcon);
        cmd.ExecuteNonQuery();
结果报错:无法绑定由多个部分组成的标识符 "a.property_num"。 我这样写好像也只能更新a表的数据 请问各位大侠有什么方法么?
ems_xp  as a
yzf86211861 2017-11-29
  • 打赏
  • 举报
回复
学会 调试 string update = "update ems_xp set a.property_num='" + this.资产.Value + "',a.Section_num='" + this.部门管理编号.Value + "',a.sn='" + this.序列号.Value + "',b.ip='" + this.IP地址.Value + "',b.mac='" + this.MAC.Value + "',b.hostname='" + this.电脑名.Value + "',a.model='" + this.型号.Value + "',a.type_s='" + this.类型.Value + "',a.Supplier='" + this.品牌.Value + "',a.cpu='" + this.CPU.Value + "',a.hdd='" + this.硬盘.Value + "',a.memory='" + this.内存.Value + "',a.statuss='" + this.资产状态.Value + "',a.takes='" + this.使用担当.Value + "',a.contact='" + this.联络员.Value + "',a.Acquire_date='" + this.取得日期.Value + "',a.update_time='" + this.更新日期.Value + "',a.position='" + this.位置.Value + "',a.is_null='" + this.资产有无.Value + "',a.is_num='" + this.有无标签.Value + "',b.floor='" + this.楼层.Value + "' from ems_xp as a inner join macip as b on a.property_num=b.bh"; 在这里加个断点 SqlCommand cmd=new SqlCommand(update,strcon); cmd.ExecuteNonQuery(); 把 update 添加监控 ,拿出来 上面的 SQL 语句 拿到 SQL 查询分析器 里面执行一下 看哪儿报错.
正怒月神 版主 2017-11-29
  • 打赏
  • 举报
回复
string update = "update  ems_xp a set a.property_num='" + this.资产.Value + "',a.Section_num='" + this.部门管理编号.Value + "',a.sn='" + this.序列号.Value + "',b.ip='" + this.IP地址.Value + "',b.mac='" + this.MAC.Value + "',b.hostname='" + this.电脑名.Value + "',a.model='" + this.型号.Value + "',a.type_s='" + this.类型.Value + "',a.Supplier='" + this.品牌.Value + "',a.cpu='" + this.CPU.Value + "',a.hdd='" + this.硬盘.Value + "',a.memory='" + this.内存.Value + "',a.statuss='" + this.资产状态.Value + "',a.takes='" + this.使用担当.Value + "',a.contact='" + this.联络员.Value + "',a.Acquire_date='" + this.取得日期.Value + "',a.update_time='" + this.更新日期.Value + "',a.position='" + this.位置.Value + "',a.is_null='" + this.资产有无.Value + "',a.is_num='" + this.有无标签.Value + "',b.floor='" + this.楼层.Value + "' from  ems_xp as c inner join macip as b on c.property_num=b.bh";
        SqlCommand cmd=new SqlCommand(update,strcon);
        cmd.ExecuteNonQuery();
snlixing 2017-11-29
  • 打赏
  • 举报
回复
直接 update  a 试试
insus 2017-11-29
  • 打赏
  • 举报
回复
尝试使用事务,2张表分别更新。 或者是把值传入存储过程来处理。
return false 2017-11-28
  • 打赏
  • 举报
回复
引用 2楼daixf_csdn 的回复:
少些了a update ems_xp set update ems_xp a set
这样写不行,sql语句直接报错 a附近有语法错误
return false 2017-11-28
  • 打赏
  • 举报
回复
引用 1楼aierda 的回复:
update ems_xp a set a.property_num=''
这样写不行,sql语句直接报错 a附近有语法错误
圣殿骑士18 2017-11-28
  • 打赏
  • 举报
回复
少些了a update ems_xp set update ems_xp a set
aierda 2017-11-28
  • 打赏
  • 举报
回复
update ems_xp a set a.property_num=''
.NET Framework 4.0 常用类库参考手册 [微软官方 MSDN] MSDN Library - .NET Framework 4.0 - 命名空间 (节选版) 制作成了chm格式,方便离线状态下学习! ======================================= 原文地址:http://msdn.microsoft.com/zh-cn/library/ms229335.aspx ======================================= .NET Framework 类库 - 命名空间 (节选版) Microsoft.Win32 提供两种类型的类:处理由操作系统引发的事件的类和对系统注册进行操作的类。 System 包含用于定义常用值和引用数据类型、事件和事件处理程序、接口、特性和处理异常的基础类和基类。其他类提供支持下列操作的服务:数据类型转换,方法参数操作,数学计算,远程和本地程序调用,应用程序环境管理以及对托管和非托管应用程序的监管。 System.Collections 包含定义各种对象集合(如列、队列、位数组、哈希和字典)的接口和类。 System.Data 包含组成大部分 ADO.NET 结构的类。ADO.NET 结构使您可以生成可用于有效管理来自多个数据源的数据的组件。 System.Data.Common 包含由 .NET Framework 数据提供程序共享的类。.NET Framework 数据提供程序描述用于在托管空间中访问数据源(如数据库)的类的集合。 System.Data.Linq 包含支持在 LINQ to SQL 应用程序中与关系数据库进行交互的类。 System.Data.Linq.Mapping 包含用于生成示关系数据库的结构和内容的 LINQ to SQL 对象模型的类。 System.Data.Mapping 提供用于存储数据映射信息的类型。 System.Data.Metadata.Edm 包含一组类型,这些类型示模型中由实体框架使用的概念,以及一组帮助应用程序使用元数据的类。 System.Data.Objects 包含可访问对象服务的核心功能的类。 System.Data.Objects.DataClasses 包含以下这些类:Entity Data Model (EDM) 中定义的类型的基类、由导航属性返回的类型的基类,以及用于定义将公共语言运行时 (CLR) 对象映射到概念模型中类型的特性的类。 System.Data.Sql 包含支持特定于 SQL Server 的功能的类。此类的 API 扩展已添加到 SQL Server 的 .NET Framework 数据提供程序 ( System.Data.SqlClient) 中。 System.Data.SqlClient 包含封装 SQL Server .NET Framework 数据提供程序的类。SQL Server .NET Framework 数据提供程序描述了用于在托管空间中访问 SQL Server 数据库的类集合。 System.IO 包含允许对数据流和文件进行同步和异步读写的类型。 System.Linq 包含支持使用语言集成查询 (LINQ) 的查询的类和接口。 System.Web 提供启用浏览器/服务器通信的类和接口。 ……

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧