none
ado插入access数据库出错 RRS feed

  • 问题

  • <%
    set conn=server.createobject("adodb.connection")
    conn.provider="microsoft.jet.oledb.4.0"
    conn.open server.mappath("demo.mdb")
    
    conn.execute "insert into accountinformation(account,password) values ('thorlong','1234456')"
    conn.close 
    %>

    运行这个代码总是报错,错误如图

    但是运行删除就可以正常运行,并且我把这个插入sql语句放在access里面运行,也是可以执行插入的。不明白什么原因。


    雷神

    2018年7月12日 14:09

全部回复

  • account,password是Access的关键(reserved word)字,应该用方括号包起来

    insert into accountinformation([account],[password]) values ('thorlong','1234456')

    参考这里

    https://stackoverflow.com/questions/1783486/ms-access-insert-into-statement

    I believe date is a reserved word. You need to encapsulate the reserved field names in square brackets:

    INSERT INTO bs1 (teacher, subject, [date], period) VALUES ('test', 'test', 'test', 'test')

    EDIT: See the following article for a complete list of reserved words in Access 2002 and greater:http://support.microsoft.com/kb/286335

    access的关键字清单

    https://support.microsoft.com/zh-cn/help/286335/list-of-reserved-words-in-access-2002-and-in-later-versions-of-access

    <section applies-to-saps="[]" aria-hidden="false" class="section ng-scope" data-before="" data-grid="col-12" ng-attr-id="{{contentSection.meta.id}}" ng-class="{'internal-content': isInternalSection(), 'flighted-content': shouldHighlightFlight }" ng-if="typeof(contentSection) !== 'string'" ng-show="shouldShow" style="box-sizing:border-box;zoom:1;float:left;min-height:1px;width:1047.34px;margin-bottom:12px;">
    -A
    ADD
    ALL
    Alphanumeric
    ALTER
    AND
    ANY
    Application
    AS
    ASC
    Assistant
    AUTOINCREMENT
    Avg
    -B
    BETWEEN
    BINARY
    BIT
    BOOLEAN
    BY
    BYTE
    -C
    CHAR, CHARACTER
    COLUMN
    CompactDatabase
    CONSTRAINT
    Container
    Count
    COUNTER
    CREATE
    CreateDatabase
    CreateField
    CreateGroup
    CreateIndex
    CreateObject
    CreateProperty
    CreateRelation
    CreateTableDef
    CreateUser
    CreateWorkspace
    CURRENCY
    CurrentUser
    -D
    DATABASE
    DATE
    DATETIME
    DELETE
    DESC
    Description
    DISALLOW
    DISTINCT
    DISTINCTROW
    Document
    DOUBLE
    DROP
    -E
    Echo
    Else
    End
    Eqv
    Error
    EXISTS
    Exit
    -F
    FALSE
    Field, Fields
    FillCache
    FLOAT, FLOAT4, FLOAT8
    FOREIGN
    Form, Forms
    FROM
    Full
    FUNCTION
    -G
    GENERAL
    GetObject
    GetOption
    GotoPage
    GROUP
    GROUP BY
    GUID
    -H
    HAVING
    -I
    Idle
    IEEEDOUBLE, IEEESINGLE
    If
    IGNORE
    Imp
    IN
    INDEX
    Index, Indexes
    INNER
    INSERT
    InsertText
    INT, INTEGER, INTEGER1, INTEGER2, INTEGER4
    INTO
    IS
    -J
    JOIN
    -K
    KEY
    -L
    LastModified
    LEFT
    Level
    Like
    LOGICAL, LOGICAL1
    LONG, LONGBINARY, LONGTEXT
    </section>
    <section applies-to-saps="[]" aria-hidden="false" class="section ng-scope" data-before="" data-grid="col-12" ng-attr-id="{{contentSection.meta.id}}" ng-class="{'internal-content': isInternalSection(), 'flighted-content': shouldHighlightFlight }" ng-if="typeof(contentSection) !== 'string'" ng-show="shouldShow" style="box-sizing:border-box;zoom:1;float:left;min-height:1px;width:1047.34px;margin-bottom:12px;">

    -M
    Macro
    Match
    Max, Min, Mod
    MEMO
    Module
    MONEY
    Move
    -N
    NAME
    NewPassword
    NO
    Not
    Note
    NULL
    NUMBER, NUMERIC
    -O
    Object
    OLEOBJECT
    OFF
    ON
    OpenRecordset
    OPTION
    OR
    ORDER
    Orientation
    Outer
    OWNERACCESS
    -P
    Parameter
    PARAMETERS
    Partial
    PERCENT
    PIVOT
    PRIMARY
    PROCEDURE
    Property
    -Q
    Queries
    Query
    Quit
    -R
    REAL
    Recalc
    Recordset
    REFERENCES
    Refresh
    RefreshLink
    RegisterDatabase
    Relation
    Repaint
    RepairDatabase
    Report
    Reports
    Requery
    RIGHT
    -S
    SCREEN
    SECTION
    SELECT
    SET
    SetFocus
    SetOption
    SHORT
    SINGLE
    SMALLINT
    SOME
    SQL
    StDev, StDevP
    STRING
    Sum
    -T
    TABLE
    TableDef, TableDefs
    TableID
    TEXT
    TIME, TIMESTAMP
    TOP
    TRANSFORM
    TRUE
    Type
    -U
    UNION
    UNIQUE
    UPDATE
    USER
    -V
    VALUE
    VALUES
    Var, VarP
    VARBINARY, VARCHAR
    VERSION
    -W
    WHERE
    WITH
    Workspace
    -X
    Xor
    -Y
    Year
    YES
    YESNO
    </section>


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2018年7月13日 0:01