【问题标题】:Look for existing entry in database before trying to insert在尝试插入之前在数据库中查找现有条目
【发布时间】:2016-08-09 13:45:58
【问题描述】:

我目前正在使用 Access 2013。我已经建立了一个数据库,该数据库围绕着提交工作的申请人。数据库的设置使一个人可以申请许多不同的工作,当同一个人通过我们的网站(使用 JotForms)申请工作时,它会自动更新数据库。

我有一个 Python 脚本从更新数据库的电子邮件中提取申请人提交信息。我遇到的问题是,在数据库中,我将申请人的主要电子邮件设置为“无重复”,因此不允许同一个人申请许多不同的工作,因为 Python 脚本试图在导致错误的数据库。

在我的访问表单 (VBA) 或 Python 中,如果主要电子邮件相同,我需要写什么来告诉我的数据库,仅在与人员主要电子邮件相关的表中创建一个新记录?

表格:

tblPerson_Information   tblPosition_Applied_for
Personal_ID  (PK)       Position_ID
First_Name              Position_Personal_ID (FK)
Last_Name               Date_of_Submission
Clearance_Type
Primary_Phone
Primary_email
Education_Level

【问题讨论】:

    标签: python database vba ms-access ms-access-2013


    【解决方案1】:

    只需在 [tblPerson_Information] 表中查找电子邮件地址:

    primary_email = 'gord@example.com'  # test data
    
    crsr = conn.cursor()    
    sql = """\
    SELECT Personal_ID FROM tblPerson_Information WHERE Primary_email=?
    """
    crsr.execute(sql, (primary_email))
    row = crsr.fetchone()
    if row is not None:
        personal_id = row[0]
        print('Email found: tblPerson_Information.Personal_ID = {0}'.format(personal_id))
    else:
        print('Email not found in tblPerson_Information')
    

    【讨论】:

    • 谢谢,我会在我的脚本中试试这个,看看它是如何工作的。
    猜你喜欢
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 2014-03-16
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多