访问插入语句 [英] access insert statement

查看:62
本文介绍了访问插入语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯了SQL Server,没有Access,但这一件事必须在

Access中完成。你可以根据语法告诉我这个查询是否有效吗?

我正在尝试在数据库中创建一个新行,在一个表中,以及主要的

key是一个名为PersonalID的自动编号。这是在第二页,

显示在个人填写了第一页上的一些信息后,然后

使用POST提交表格。数据库名称为Shape,表名为

Personal。

----------------------- ------------------------------------------------ <无线电通信/>
DB_CONNECTIONSTRING =" DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ =" &安培; _

Server.Mappath(" Shape.mdb")& ""


设置objRecordset = Server.CreateObject(" ADODB.Recordset")

objRecordset.Open" Shape",DB_CONNECTIONSTRING,adOpenStatic ,

adLockPessimistic,adCmdTable

strFirstName = Replace(Trim(Request.Form(" FirstName"))),"''"," '''''")

strLastname =替换(修剪(Request.Form(" LastName"))),"''",'''''")


strSQL =" set nocount on; INSERT INTO Personal(FirstName,LastName)VALUES

(strFirstName,strLastName);选择@@ identity [newid];"

设置rs = objConnection.execute(strSQL)

strPersonalID = RS(" newid")

rs.Close

解决方案

你试过吗?是否有错误?


我不确定Access是否有@@ identity....


我'建议尝试并发布具体的错误。


-

----------------- -----------------------------------------

Curt Christianson(Software_AT_Darkfalz.Com)

所有者/首席设计师,DF-Software
http://www.Darkfalz.com

--------------------------- ------------------------------

...提供免费脚本&每个人的代码snippits ...

----------------------------------- ----------------------

" middletree" < MI ******** @ htomail.com>在消息中写道

新闻:uC ************* @ TK2MSFTNGP11.phx.gbl ...

我习惯了SQL Server ,没有Access,但这一件事必须在
Access中完成。根据语法,你能告诉我这个查询是否有效吗?我正在尝试在一个表中创建数据库的新行,而
主键是一个名为的autonumber个人身份证件。这是在第二页上,在个人填写了第一页上的一些信息后显示,然后使用POST提交表格。数据库名称为Shape,表名为
Personal。

--------------------------- --------------------------------------------
DB_CONNECTIONSTRING = DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ =" &安培; _
Server.Mappath(" Shape.mdb")& &;;"

设置objRecordset = Server.CreateObject(" ADODB.Recordset")
objRecordset.Open" Shape",DB_CONNECTIONSTRING,adOpenStatic,
adLockPessimistic,adCmdTable

strFirstName =替换(修剪(Request.Form(" FirstName"))),"''","''''")
strLastname =替换(修剪) (Request.Form(" LastName")),"''","''''")

strSQL =" set nocount on; INSERT INTO Personal(FirstName,LastName)
VALUES(strFirstName,strLastName);选择@@ identity [newid];"
设置rs = objConnection.execute(strSQL)
strPersonalID = RS(" newid")
rs.Close


Curt_C [MVP]写道:

你试过吗?是不是有错误?

我不确定Access是否有@@ identity....



FYI,它确实如此Jet 4.0


Bob


当我发布时,我还没有尝试过。正在寻找是否有明显错误的事情。


事实证明,它失败了,但我不明白为什么。更重要的是,它并没有好像b $ b似乎与身份有任何关系。


这里是错误:


a ..错误类型:

用于ODBC驱动程序的Microsoft OLE DB提供程序(0x80004005)

[Microsoft] [ODBC Microsoft Access驱动程序]一般错误无法打开

注册表项''临时(易失性)Jet DSN进程0x3b8线程0x65c

DBC 0x1774064 Jet''。

/grace/shapethankyou.asp,line 11

第11行是:


objRecordset.Open" Shape",DB_CONNECTIONSTRING,adOpenStatic,

adLockPessimistic,adCmdTable


" Curt_C [MVP]" < software_AT_darkfalz.com>在消息中写道

新闻:#Y ************** @ TK2MSFTNGP10.phx.gbl ...

你试过吗?是否有错误?

我不确定Access是否有@@ identity....

我建议您尝试并发布具体错误。

-
--------------------------------- -------------------------
Curt Christianson(Software_AT_Darkfalz.Com)
所有者/首席设计师,DF-Software
http://www.Darkfalz.com
----- -------------------------------------------------- -
..提供免费脚本&每个人的代码snippits ......
--------------------------------------- ------------------

" middletree" < MI ******** @ htomail.com>在消息中写道
新闻:uC ************* @ TK2MSFTNGP11.phx.gbl ...

我习惯了SQL Server,没有Access,但这一件事必须在
Access中完成。你能否根据语法告诉我这个查询是否有效?

我正在尝试在数据库中创建一个新行,在一个表中,


primary < blockquote class =post_quotes> key是一个名为PersonalID的自动编号。这是在第二页上,
显示在个人填写了第一页上的一些信息之后,
然后使用POST提交了表格。数据库名称为Shape,表格为
,名为Personal。

--------------------------- --------------------------------------------
DB_CONNECTIONSTRING = DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ =" &安培;
_ Server.Mappath(" Shape.mdb")& &;;"

设置objRecordset = Server.CreateObject(" ADODB.Recordset")
objRecordset.Open" Shape",DB_CONNECTIONSTRING,adOpenStatic,
adLockPessimistic,adCmdTable

strFirstName =替换(修剪(Request.Form(" FirstName"))),"''","''''")
strLastname =替换(修剪) (Request.Form(" LastName")),"''","''''")

strSQL =" set nocount on; INSERT INTO Personal(FirstName,LastName)


VALUES

(strFirstName,strLastName);选择@@ identity [newid];"
设置rs = objConnection.execute(strSQL)
strPersonalID = RS(" newid")
rs.Close



I am used to SQL Server, no Access, but this one thing has to be done in
Access. Can you tell me if this query will work, based on the syntax?

I am trying create a new row on the database, in one table, and the primary
key is an Autonumber called PersonalID. This is on the second page, which
shows after the personal has filled out some info on the first page, then
submitted the form using POST. Database name is Shape, and table is named
Personal.
-----------------------------------------------------------------------
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
Server.Mappath("Shape.mdb") & ";"

Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "Shape", DB_CONNECTIONSTRING, adOpenStatic,
adLockPessimistic, adCmdTable

strFirstName = Replace(Trim(Request.Form("FirstName")),"''","''''")
strLastname = Replace(Trim(Request.Form("LastName")),"''","''''")

strSQL = "set nocount on; INSERT INTO Personal(FirstName,LastName) VALUES
(strFirstName,strLastName); select @@identity [newid];"
Set rs=objConnection.execute (strSQL)
strPersonalID = RS("newid")
rs.Close

解决方案

have you tried? was there an error?

I''m not sure that Access has the "@@identity"....

I''d suggest trying and posting the specific errors.

--
----------------------------------------------------------
Curt Christianson (Software_AT_Darkfalz.Com)
Owner/Lead Designer, DF-Software
http://www.Darkfalz.com
---------------------------------------------------------
...Offering free scripts & code snippits for everyone...
---------------------------------------------------------
"middletree" <mi********@htomail.com> wrote in message
news:uC*************@TK2MSFTNGP11.phx.gbl...

I am used to SQL Server, no Access, but this one thing has to be done in
Access. Can you tell me if this query will work, based on the syntax?

I am trying create a new row on the database, in one table, and the primary key is an Autonumber called PersonalID. This is on the second page, which
shows after the personal has filled out some info on the first page, then
submitted the form using POST. Database name is Shape, and table is named
Personal.
-----------------------------------------------------------------------
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
Server.Mappath("Shape.mdb") & ";"

Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "Shape", DB_CONNECTIONSTRING, adOpenStatic,
adLockPessimistic, adCmdTable

strFirstName = Replace(Trim(Request.Form("FirstName")),"''","''''")
strLastname = Replace(Trim(Request.Form("LastName")),"''","''''")

strSQL = "set nocount on; INSERT INTO Personal(FirstName,LastName) VALUES (strFirstName,strLastName); select @@identity [newid];"
Set rs=objConnection.execute (strSQL)
strPersonalID = RS("newid")
rs.Close



Curt_C [MVP] wrote:

have you tried? was there an error?

I''m not sure that Access has the "@@identity"....


FYI, it does as of Jet 4.0

Bob


I hadn''t tried yet when I posted that. Was looking to see if there was
something obviously wrong.

As it turned out, it failed, but I have no idea why. What''s more, it doesn''t
seem to have anything to do with identity.

Here''s the error:

a.. Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open
registry key ''Temporary (volatile) Jet DSN for process 0x3b8 Thread 0x65c
DBC 0x1774064 Jet''.
/grace/shapethankyou.asp, line 11

Where line 11 is:

objRecordset.Open "Shape", DB_CONNECTIONSTRING, adOpenStatic,
adLockPessimistic, adCmdTable

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:#Y**************@TK2MSFTNGP10.phx.gbl...

have you tried? was there an error?

I''m not sure that Access has the "@@identity"....

I''d suggest trying and posting the specific errors.

--
----------------------------------------------------------
Curt Christianson (Software_AT_Darkfalz.Com)
Owner/Lead Designer, DF-Software
http://www.Darkfalz.com
---------------------------------------------------------
..Offering free scripts & code snippits for everyone...
---------------------------------------------------------
"middletree" <mi********@htomail.com> wrote in message
news:uC*************@TK2MSFTNGP11.phx.gbl...

I am used to SQL Server, no Access, but this one thing has to be done in
Access. Can you tell me if this query will work, based on the syntax?

I am trying create a new row on the database, in one table, and the


primary

key is an Autonumber called PersonalID. This is on the second page, which shows after the personal has filled out some info on the first page, then submitted the form using POST. Database name is Shape, and table is named Personal.
-----------------------------------------------------------------------
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _ Server.Mappath("Shape.mdb") & ";"

Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "Shape", DB_CONNECTIONSTRING, adOpenStatic,
adLockPessimistic, adCmdTable

strFirstName = Replace(Trim(Request.Form("FirstName")),"''","''''")
strLastname = Replace(Trim(Request.Form("LastName")),"''","''''")

strSQL = "set nocount on; INSERT INTO Personal(FirstName,LastName)


VALUES

(strFirstName,strLastName); select @@identity [newid];"
Set rs=objConnection.execute (strSQL)
strPersonalID = RS("newid")
rs.Close




这篇关于访问插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆