当前位置:编程学习 > asp >>

求助,ASP(vbscript)中连接MYSQL数据库出错:ODBC 驱动程序不支持所需的属性

代码如下: <% dim point dim belong dim explain dim typ dim rs dim str dim str1 dim stl point=request.form("pt") belong=request.form("bl") explain=request.form("epl") typ=request.form("tp") set rs=server.createobject("adodb.recordset") if typ=1 then stl="jnknl" else stl="snknl" end if 'str="select * from " & stl & " where point='" & point & "'" ’代码出错在这里 str="select * from snknl where point ='西周'" '这个是对比,发现条件里用中文就出错,数字和英文字符就没有问题 rs.open str,cn,1,1 'if rs.bof and rs.eof 'else ' response.redirect "addpoint.asp?errstr=已有相同记录" ' rs.close ' set rs=nothing ' response.end() 'end if 'rs.close str1="insert into " & stl & "(point,belong,epl) values('" & point & "','" & belong & "','" & explain & "')" response.write(str & "<br>") 'response.write(str3 & "<br>") response.write err.number response.write("<br>") response.write err.description response.end() 'rs.open str1,cn,3,2 'rs.close rs.open str,cn,3,2 if rs.eof or rs.bof then response.redirect "addpoint.asp?errstr=未成功添加记录" rs.close set rs=nothing response.end() else response.redirect "addpoint.asp?errstr=已成功添加记录" rs.close set rs=nothing response.end() end if %> 编码用的是GB2312 求高手指点如何解决,谢谢!
补充:已解决,我在rs.open前加了个rs.cursorlovation=3后解决。
答案:你在与数据库建立连接后加一句(一般是在 cn.open ... 这句的下面)
cn.execute "SET NAMES 'GB2312';"
MySQL的默认编码格式不是GB2312,你加了上面那句一般就可以了。
你也可以进入MySQL的管理界面,把编码格式改为GB2312就一劳永逸了。
此外MySQL与MSSQL或ACCESS的SQL语法是有一些差别的,如果你是第一次用,最好先去弄清楚。
其他:str="select * from " & stl & " where point='" & point & "'" 
你把这句话 先打出来看一下,
response.write str
这样你就知道你的sql语句有没有问题
str="select * from snknl where point ='西周'" 这里你到mysql中去运行下,看看能不能正确查询,如果可以的话,有可能是你的页面保存格式为UTF-8,你用记事本打开并另存为ANSI格式看下. 

上一个:用asp.net编写的web程序开发中如何决定使用html控件 还是web控件
下一个:求免费ASP整站程序

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,