#鸿蒙学习大百科#关系型数据库如何实现update操作?

关系型数据库如何实现update操作?

HarmonyOS
2024-10-23 11:34:54
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
耗子煨汁r
import { ValuesBucket } from '@ohos.data.ValuesBucket';
import { relationalStore } from '@kit.ArkData';
import { BusinessError } from '@kit.BasicServicesKit';

let store: relationalStore.RdbStore | undefined = undefined;
@Entry
@Component
struct Index {
  build() {
    Column() {
      Button("update").onClick(() => {
        const valueBucket: ValuesBucket = {
          NAME:"TOM",
          AGE: 12,
          SALARY: 100.5,
          CODES:  new Uint8Array([1, 2, 3, 4, 5]),
        };
        //获取store步骤省略
        // 修改数据
        let predicates = new relationalStore.RdbPredicates('People'); // 创建表'People'的predicates
        predicates.equalTo('NAME', 'JASON'); // 匹配表'People'中'NAME'为'JASON'的字段,将NAME为JASON的数据改为valueBucket中对应的值
        if (store !== undefined) {
          (store as relationalStore.RdbStore).update(valueBucket, predicates, (err: BusinessError, rows: number) => {
            if (err) {
              console.error(`Failed to update data. Code:${err.code}, message:${err.message}`);
              return;
            }
            console.info(`Succeeded in updating data. row count: ${rows}`);
          })
        }
      })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
分享
微博
QQ
微信
回复
2024-10-23 17:13:38
相关问题
HarmonyOS 关系数据库如何批量update?
200浏览 • 1回复 待解决