连接数据库问题:我用OLEDB进行数据库连接时候,为什么不能对数据库表中的数据进行修改,更新,添加操作呢???代码如下
<%dim conn
Set conn=Server.CreateObject("ADODB.Connection")
DBPath=server.mappath("db/mydb.asa")
conn.Open "provider=microsoft.jet.oledb.4.0;data source=" & DBPath%>
添加语句如下:
<%sql = "Insert Into userinf (username,password,name,userdept,userlevel) Values( "
sql = sql & SqlStr(username) & ", "
sql = sql & SqlStr(password) & ", "
sql = sql & SqlStr(realname) & ", "
sql = sql & SqlStr(userdept) & ", "
sql = sql & SqlStr(userlevel) & ")"
conn.Execute(sql)
set rs1=server.createobject("adodb.recordset")
sql="SELECT @@IDENTITY AS IdSum from userinf"
rs1.open sql,conn,1
IdSum=rs1("IdSum")
set rs1=nothing
if err.number<>0 then
conn.rollbacktrans
call DispErrorInfo1("对不起,增加用户出错!出错原因:"&err.description)
conn.close
set conn=nothing
response.end
%>
结果提示语法错误:
对不起,增加用户出错!出错原因:INSERT INTO 语句的语法错误
可是我改成
dim conn
Set conn=Server.CreateObject("ADODB.Connection")
DBPath=server.mappath("db/mydb.asa")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
连接数据库就OK了,
大家说咋回事????????????????????
请各位大哥大姐详细分析一下....感激不尽
[此贴子已经被作者于2006-8-12 11:54:03编辑过]