如题。我的界面有个edit,现在要在buttononclick里将edit.text值post进数据库表里。但是该字段为 primary key。问如何在写入前判断该值是否已存在数据表里。
用query吗?

解决方案 »

  1.   

    if query.recordcount=0 then
      

  2.   

    應該再query一次,才能前台提示出來
      

  3.   

    query....select * from tablename where id='''+edit1.text+'''
    ...if query1.recordcount<0 then
    ...insert
      

  4.   

    上述判断查询结果是否为空有时是不灵的,某些后台数据库的RecordCount及RecNo总是零;可以换成
    if Query1.Eof=Query1.Bof then
      

  5.   

    if Query1.Eof=Query1.Bof then
      

  6.   

    query....select Count(*) a1 from tablename where id='''+edit1.text+'''
    ...if query1.FieldByName('a1').asinteger=<0 then
    ...insert
      

  7.   

    ……
    select * from tablename where id='''+edit1.text+'''
    ……
    if Query1.Eof=Query1.Bof then