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

数据库为空,为什么总是不能插入数据?
数据库为空,为什么总是不能插入数据?
这段代码有什么问题
sub   AddCount()  
dim   sql,irs
dim   conn
dim   connstr
db= "WryData.mdb "   '数据库文件位置
on   error   resume   next
connstr= "DBQ= "+server.mappath( " "&db& " ")+ ";DefaultDir=;DRIVER={Microsoft   Access   Driver   (*.mdb)}; "
set   conn=server.createobject( "ADODB.CONNECTION ")
if   err   then
err.clear
else
conn.open   connstr
end   if
sql= "select   ClickCount   from   country   where   countryName= "   &   clientCountry
Set   irs=conn.Execute(sql)
If   irs.eof   And   irs.bof   Then  
sql= "Insert   into   Country(countryName,ClickCount)   values( 'wef ',   '1 ') "
set   a=conn.Execute(sql)
Else
Do   While   Not   irs.eof
sql= "update   Country   set   ClickCount   = "   &   irs( "ClickCount ")+1   & "   where   CountryName   = "   &   clientCountry
set   a=conn.Execute(sql)
irs.movenext  
Loop
End   If  
sql= "Insert   into   Country(countryName,ClickCount)   values( 'wef ',   '1 ') "
set   a=conn.Execute(sql)
a.close
set   a=nothing
irs.close  
Set   irs=nothing  
Set   conn=Nothing  
End   sub

------解决方案--------------------
整型不用单引号的。
sql= "Insert into Country(countryName,ClickCount) values( 'wef ', 1) "
------解决方案--------------------
on error resume next
把这句话去掉 看看哪里出错
------解决方案--------------------
sql= "select ClickCount from country where countryName= " & clientCountry

sql语句错误,
应该改为:

sql= "select ClickCount from country where countryName= ' " & clientCountry& " ' "