admin管理员组文章数量:1794759
access 数据更新update
(1)单表内字段更新
update PipeLine set state='0' where Address='33'
(2)两个表间关联更新
在access数据库中,UPDATE指令不能够含有From语句。因此在多表关联批量更新数据时操作不是那么方便。
update table1 as t1,table2 as t2 set t1.name=t2.name where t1.id=t2.id ; 用Where语句不好使的情况下,可以使用INNER JOIN 语句。
update table1 t1 inner join table2 t2 on t1.id=t2.id set t1.name=t2.name;
(3)单表内带分支条件的更新 update 表 set A = (case when B=满足一定的条件 then '111' else '222' end)
update SMDTV_632 set symbolID= (case when Subsid='检查井' then '908008' when Subsid='雨水口' then '908013' end ) update SMDTV_632 set symbolID= (case when Subsid='检查井' then '908008' when Subsid='雨水口' then '908013' else '0' end )
当 S_X>E_X时,tmp1取(S_Lat,E_Lat)的最大值,反之,S_X<E_X时取最小值 update pipeline set tmp1= (case when S_X>E_X then (case when S_Lat<E_Lat then E_Lat else S_Latend) else (case when S_Lat<E_Lat then S_Lat else E_Lat end) end)
(4)两表内带分支条件的更新
update a set A=case when b.xxx='xxx' then '111' else '222' end from a join b on a.id=b.id
(5)带判断条件的更新
update PSLINE Set Code= iif(Type='PSYS',"4000",iif(Type='PSWS',"4100","4200"))
(6)数据为空时,给数据设置默认值
update psline t set t.S_Deep = '1' where t.S_Deep is null
(7)大量数据更新时,用datatable 更新整个access数据表
public void UpdateAccess( DataTable temp, string tablename) { OleDbConnection dconn = project.getOdbConn(); OleDbDataAdapter Bada = new OleDbDataAdapter(string.Format("SELECT * FROM {0} where 1 =2", tablename), dconn);//建立一个DataAdapter对象 OleDbCommandBuilder cb = new OleDbCommandBuilder(Bada);//这里的CommandBuilder对象一定不要忘了,一般就是写在DataAdapter定义的后面 cb.QuotePrefix = "["; cb.QuoteSuffix = "]"; DataSet ds = new DataSet();//建立DataSet对象 Bada.Fill(ds, "demo");//填充DataSet foreach (DataRow tempRow in temp.Rows) { DataRow dr = ds.Tables["demo"].NewRow(); dr.ItemArray = tempRow.ItemArray;//行复制 ds.Tables["demo"].Rows.Add(dr); } Bada.Update(ds, "demo");//用DataAdapter的Update()方法进行数据库的更新 }
版权声明:本文标题:access 数据更新update 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686966539a123324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论