您的位置:首页 > 编程语言 > ASP

【asp+数据库】如何把字符"1+2" 让它等于3?以及解决办法

2008-11-22 12:08 411 查看
数据库代码如下:
---------------------
create database test

use test

create table test_gongshi
(
name varchar(100),--标记
x varchar(1000),--x
y varchar(1000),--y
z varchar(1000),--z
n varchar(1000),--n
)

insert into test_gongshi values('门边','a+b','b+c','c+d','0')

select * from test_gongshi
---------------------

---------------------
页面代码如下:
---------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%
set conn=server.CreateObject("adodb.connection")
str="Driver={SQL Server};server=(local);uid=qi;pwd=13940282230;database=test"
conn.open(str)

sql="select * from test_gongshi"
set rs=conn.execute(sql)
a=1
b=2
c=3
d=4

gongshi=replace(rs("x"),"a",a)'注:此处 rs("x")=a+b
gongshi=replace(gongshi,"b",b)
response.Write(gongshi)
'response.Write(rs("x"))
response.Write("<br>")
gongshi2=replace(rs("y"),"b",b)
gongshi2=replace(gongshi2,"+",+)
gongshi2=replace(gongshi2,"c",c)
response.Write(gongshi2)
%>

</body>
</html>
-------------------------

解决办法





------------------------

<%
Set x = CreateObject("MSScriptControl.ScriptControl")
x.Language = "VBScript"
a = 1
b = 2
c = 3
d = 4

gongshi = Replace("a+b", "a", a) '变量自己替换了哈,相信你会的
gongshi = Replace(gongshi, "b", b)
result = x.Eval(gongshi)
response.write gongshi & "=" & result
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐