1、通过XML完成数据表数据的更新
CREATE TABLE Employee(eid int, fname varchar(20), lname varchar(20))
INSERT INTO Employee VALUES (1, 'Nancy', 'Davolio')
INSERT INTO Employee VALUES (2, 'Andrew', 'Fuller')
DECLARE @hDoc int
exec sp_xml_preparedocument @hDoc OUTPUT,
'<root>
<employee eid="1" lname="dfsd" fname="sdfsd" />
</root>'
UPDATE employee
SET
employee.fname = XMLEmployee.fname,
employee.lname = XMLEmployee.lname
FROM OPENXML(@hDoc, '/root/employee')
WITH employee XMLEmployee
WHERE employee.eid = XMLEmployee.eid
SELECT * from employee
2、在Northwind数据库的Employees表中实现同样的功能,总是提示“列EmployeeID不存在”。经查证,该列设置了IDENTITY属性,所以提示出错,做以下修改可以完成目的。
declare @handle int
exec sp_xml_preparedocument @handle output,
'<root>
<Employees EmployeeID="2" LastName="xx"/>
</root>'
update Employees
set
Employees.lastname=xmldate.LastName
from openxml(@handle,'/root/Employees')
with (EmployeeID int,LastName char)xmldate
where Employees.EmployeeID=xmldate.EmployeeID
没有解决EmployeeID字段设置的问题,该字段在这段SQL中是否能添加IDENTITY属性,格式应该是怎样???
<script language="JavaScript" type="text/javascript"> function SendLinkByEMail(url, name) { var action = "SendLink("; action = action + "TITLE="; action = action + name; action = action + "&URL="; action = action + url; action = action + ")"; parent.window.external.HandleAction(action); } </script>