#鸿蒙学习大百科#关系型数据库如何新增一条数据?

关系型数据库如何新增一条数据?

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

let store: relationalStore.RdbStore | undefined = undefined;
@Entry
@Component
struct Index {
  build() {
    Column() {
      Button("insert").onClick(() => {
        const valueBucket: ValuesBucket = {
          NAME:"TOM",
          AGE: 12,
          SALARY: 100.5,
          CODES:  new Uint8Array([1, 2, 3, 4, 5]),
        };
        //获取store步骤省略

        if (store !== undefined) {
          (store as relationalStore.RdbStore).insert('EMPLOYEE', valueBucket, (err: BusinessError, rowId: number) => {
            if (err) {
              console.error(`Failed to insert data. Code:${err.code}, message:${err.message}`);
              return;
            }
            console.info(`Succeeded in inserting data. rowId:${rowId}`);
          })
        }
      })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
分享
微博
QQ
微信
回复
2024-10-23 17:13:10


相关问题