| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 525 人关注过本帖
标题:老是提示:操作必须使用一个可更新的查询
只看楼主 加入收藏
jendy5566
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-3-18
结帖率:54.55%
收藏
已结贴  问题点数:15 回复次数:4 
老是提示:操作必须使用一个可更新的查询
我用asp做一个从Excel2003将数据导入Access2003的程序,但老是提示:操作必须使用一个可更新的查询,我已经给数据库添加来宾用户的所有权限了,也还是一样,我的程序如下,望得到高手指点:
dim conn
dim conn2
'连接目的数据表
set conn=CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Data Source=" & Server.MapPath("student.mdb")
'连接待读入excel数据表
set conn2=CreateObject("ADODB.Connection")
conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties='Excel 5.0;hdr=yes;imex=1';Data Source="& Server.MapPath("upload/"&FileName)
'查询待读入excel数据表
sql = "SELECT * FROM [Sheet1$]"
set rs = conn2.execute(sql)
'将数据循环读入目的数据库
while not rs.eof
'查询相同的数据,以学号为唯一标识
dim icount
checksamesql="select stu_no from student where stu_no = '"& fixsql(rs(0)) &"'"
set checksamers = conn.execute(checksamesql)
icount = checksamers.recordcount
checksamers.close
set checksamers= nothing

if icount<=0 then
sql = "insert into student(stu_no,stu_name,stu_sex,stu_course,stu_grade,moon) values('"& fixsql(rs(0)) &"','"& trim(fixsql(rs(1))) &"','"& fixsql(rs(2)) &"','"& fixsql(rs(3)) &"','"& fixsql(rs(4)) &"','"& fixsql(rs(5)) &"')"
conn.execute(sql)'提示在这一行出错
end if

rs.movenext
wend
set oFile=nothing'释放文件对象
next

set upfile=nothing'释放上传对象

'释放数据连接对象
conn.close
set conn = nothing
conn2.close
set conn2 = nothing

'删除上传数据表
Set fso = CreateObject("Scripting.FileSystemObject")
FiLePaTh = Server.MapPath("upload/"&FileName)
If fso.FileExists(FiLePaTh) Then
fso.DeleteFile(FiLePaTh)
end if
Set fso = nothing


response.Write "<script LANGUAGE='javascript'>alert('数据导入成功!');history.go(-1);</script>"
response.End
搜索更多相关主题的帖子: 数据库 数据表 excel 
2011-03-02 22:30
jendy5566
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-3-18
收藏
得分:0 
自己先顶!!!!!!!
2011-03-02 22:40
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
收藏
得分:11 
conn.execute(sql)'提示在这一行出错改为:
set rs=conn.execute(sql)
这样试试,如果不行完整代码打包测试了。

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2011-03-02 22:59
jendy5566
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-3-18
收藏
得分:0 
感谢版主,我试了但还是不行,以下是整个asp文件的代码,希望能再指点一下,谢谢···

<%
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,upfilecount
upfilecount=0
set upfile=new clsUp ''建立上传对象
upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;"    '设置上传类型的黑名单
upfile.GetData (1024000)   '取得上传数据,限制最大上传10M

if upfile.isErr then  '如果出错
    select case upfile.isErr
    case 1
    Response.Write "没有上传数据"
    case 2
    Response.Write "上传的文件超出限制,最大1M"
    end select
    else

    FSPath=GetFilePath(Server.mappath("updata.asp"),"\")'取得当前文件在服务器路径
    FSPath=FSPath&"upload\" '上传到upload文件夹
    ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
    for each formName in upfile.file '列出所有上传了的文件
       set oFile=upfile.file(formname)
       FileName=upfile.form(formName)'取得文本域的值
       if not FileName>"" then  FileName=oFile.filename'如果没有输入新的文件名,就用原来的文件名
       upfile.SaveToFile formname,FSPath&FileName '保存文件 也可以使用AutoSave来保存,参数一样,但是会自动建立新的文件名
   
        if upfile.iserr then
        Response.Write upfile.errmessage
        else
        upfilecount=upfilecount+1
        Response.Write "上传成功"
        end if
        
'将数据读入数据库        
              dim conn
              dim conn2
'连接目的数据表
              set conn=CreateObject("ADODB.Connection")
              conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Data Source=" & Server.MapPath("sddb.mdb")
'连接待读入excel数据表
              set conn2=CreateObject("ADODB.Connection")
              conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties='Excel 5.0;hdr=yes;imex=1';Data Source="& Server.MapPath("upload/"&FileName)
'查询待读入excel数据表
              sql = "SELECT * FROM [Sheet1$]"
              set rs = conn2.execute(sql)
'将数据循环读入目的数据库
              while not rs.eof  
              '查询相同的数据,以学号为唯一标识
              dim icount
              checksamesql="select roomno from cost_sd where roomno = '"& fixsql(rs(0)) &"'"
              set checksamers = conn.execute(checksamesql)
              icount = checksamers.recordcount
              'checksamers.close
              set checksamers= nothing

              if icount<=0 then
              sql = "insert into cost_sd(roomno,user_sd,water,eletricity,moon_sd,year_sd) values('"& fixsql(rs(0)) &"','"& trim(fixsql(rs(1))) &"','"& fixsql(rs(2)) &"','"& fixsql(rs(3)) &"','"& fixsql(rs(4)) &"','"& fixsql(rs(5)) &"')"              
              conn.execute(sql)'提示在这一行出错
              end if

              rs.movenext
              wend
              set oFile=nothing'释放文件对象
    next
   
set upfile=nothing'释放上传对象

'释放数据连接对象
conn.close
set conn = nothing
conn2.close
set conn2 = nothing

'删除上传数据表
Set fso = CreateObject("Scripting.FileSystemObject")
FiLePaTh = Server.MapPath("upload/"&FileName)
If  fso.FileExists(FiLePaTh) Then
fso.DeleteFile(FiLePaTh)
end if
Set fso = nothing


response.Write "<script LANGUAGE='javascript'>alert('数据导入成功!');history.go(-1);</script>"
response.End   
end if
'取得文件上传路径
function GetFilePath(FullPath,str)
  If FullPath <> "" Then
    GetFilePath = left(FullPath,InStrRev(FullPath, str))
    Else
    GetFilePath = ""
  End If
End function
'检查读入数据,有效性验证,可以修改你要过滤的符号
function fixsql(str)
    dim newstr
    newstr = str
    if isnull(newstr) then
        newstr = ""
    else
        newstr =Replace(newstr ,"'","‘")
        newstr =Replace(newstr ,"%","%")
        newstr =Replace(newstr ,"-","-")   
        newstr =Replace(newstr ,">","〉")
        newstr =Replace(newstr ,"<","〈")
        newstr =Replace(newstr ,"&","&amp;")
        newstr =Replace(newstr,";",";")
        newstr =Replace(newstr ,"+","+")
        newstr =Replace(newstr ,"[","[")
        newstr =Replace(newstr ,"]","]")
        newstr =Replace(newstr ,"{","{")
        newstr =Replace(newstr ,"}","}")
        newstr =Replace(newstr ,"(","(")
        newstr =Replace(newstr ,")",")")
        newstr =Replace(newstr ,"""","''")
    end if
    fixsql = newstr
end function
%>
2011-03-03 07:50
jendy5566
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-3-18
收藏
得分:0 
还是没能解决啊!!!!!
2011-03-07 22:24
快速回复:老是提示:操作必须使用一个可更新的查询
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014744 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved