日期:2014-05-17  浏览次数:20960 次

为什么 insert into access 无效
<!--   #include   file   =   "conn.asp "-->
<%
function   opendb(DBPath,sessionname,dbsort)

dim   conn
Set   conn=Server.CreateObject( "ADODB.Connection ")
DBPath1=server.mappath( "db/union.mdb ")
conn.Open   "driver={Microsoft   Access   Driver   (*.mdb)};dbq= "   &   DBPath1
set   session(sessionname)=conn
set   opendb=session(sessionname)
end   function

%>

<%
'Unionid,UrlName,UrlAddress,UrlContent,ZUserName,ZPhoto,ZResume,ZConnect,ZTofriens,ZSubmitTime
'ZChecked   审核0无1过,   ZUpdate   站长资料   修改0无1过,   ZShowed     是否显示0无1过

Dim   UrlName,UrlAddress
Dim   UrlContent,ZUserName,ZPhoto
Dim   ZResume,ZConnect,ZTofriends

UrlName   =   Request.Form( "Name ")
UrlAddress   =   Request.Form( "Address ")
UrlContent   =   Request.Form( "Cotent ")
ZUserName   =   Request.Form( "UserName ")
ZPhoto   =   Request.Form( "Photo ")
ZResume   =   Request.Form( "Resume ")
ZConnect   =   Request.Form( "Connect ")
ZTofriends   =   Request.Form( "Tofriends ")
SubTime   =   Date()

set   conn=opendb( "db ", "conn ", "accessdsn ")
    sql   =   "insert   into   [Union]   (UrlName,UrlAddress,UrlContent,ZUserName,ZPhoto,ZResume,ZConnect,ZTofriends,ZSubmitTime,ZChecked,ZUpdate,ZShowed) "
      sql   =   sql   &   "values   ( ' "&   UrlName   & " ', ' "&   UrlAddress   & " ', ' "&   UrlContent   & " ', ' "&   ZUserName   & " ', ' "&   ZPhoto   & " ', ' "&   ZConnect   & " ', ' "&   ZTofriends   & " ',# "&   SubTime   & "#,0,0,0) "

'response.Write(sql)

conn.execute(sql)
conn.close


%>

为什么不执行?数据写不到数据库

------解决方案--------------------
sql = sql & "values ( ' "& UrlName & " ', ' "& UrlAddress & " ', ' "& UrlContent & " ', ' "& ZUserName & " ', ' "& ZPhoto & " ', ' "& ZConnect & " ', ' "& ZTofriends & " ',# "& SubTime & "#,0,0,0) "
↓空格↓没有空格
sql = sql & " values( ' "& UrlName & " ', ' "& UrlAddress & " ', ' "& UrlContent & " ', ' "& ZUserName & " ', ' "& ZPhoto & " ', ' "& ZConnect & " ', ' "& ZTofriends & " ',# "& SubTime & "#,0,0,0) "