access 数据更新update

1 篇文章 0 订阅

(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()方法进行数据库的更新
        }

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值