首先说明下我的语句是asp语句,没几个人搞的明白,所以来这里问个问题!我想把表的数据写到excel里,代码如下:<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head><body><%
dim Thename
Response.ContentType = "application/vnd.ms-excel"
set conn = server.createobject ("adodb.connection")
conn.open "ASPData", "sa", "yourpassword"
Thename=Session("Name")
name=Trim(Thename)
'response.write(name)
'Response.Write("select * from util where name='"+ name+ "'")
'Set RSAllFinancialRecord=conn.Execute("select * from util where name='"&name&"'")
'Set RSRecord = conn.Execute("select * from util where name="&Trim(Session("Name")))
'Set RSAllFinancialRecord = conn.Execute("select * from util where name = 'aa' ")
Set RSAllFinancialRecord =conn.Execute("select * from util where name='"+ name+ "'")
'Set RSRecord = conn.Execute("select * from util where name="+trim(Session("Name")))%><TABLE BORDER=1 width="559"> <TR> <% ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Loop through Fields Names and print out the Field Names 
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% j = 2    'row counter For i = 0 to RSAllFinancialRecord.Fields.Count - 1 %> <TD width="80"><B><% = RSAllFinancialRecord(i).Name %></B></TD> <% Next %> 
</TR> <% ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' % Loop through rows, displaying each field ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Do While Not RSAllFinancialRecord.EOF %> <TR> <% For i = 0 to RSAllFinancialRecord.Fields.Count - 1 %> <TD VALIGN=TOP width="49"><% = RSAllFinancialRecord(i) %></TD> <% Next %> 
</TR> <% RSAllFinancialRecord.MoveNext j = j + 1 Loop ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' % Make sure to close the Result Set and the Connection object ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RSAllFinancialRecord.Close %>
</TABLE>
 </body></html>问题是这样的:1) Thename=Session("Name")
name=Trim(Thename)得到的name值是aa,如果
我以'Set RSAllFinancialRecord = conn.Execute("select * from util where name = 'aa' ")
方式执行,程序能成功执行,并能把相应的数据写到excel里。
2)我用方式Response.Write("select * from util where name='"+ name+ "'")显示出该语句是否完整正确,同时我用Set RSAllFinancialRecord =conn.Execute("select * from util where name='"+ name+ "'")就不行,
提示错误如下:
select * from util where name='aa'  Microsoft VBScript 编译器错误 错误 '800a03f6' 
缺少 'End' /iisHelp/common/500-100.asp,行242 Microsoft VBScript 运行时错误 错误 '800a01a8' 缺少对象: '' /gongsi/excle.asp,行52 请高手指点下,这是什么原因?要如何修改?

解决方案 »

  1.   

    Set RSAllFinancialRecord =conn.Execute("select * from util where [name]='"+ name+ "'")
    必须保证name有值
      

  2.   

    我用Response.Write("select * from util where name='"+ name+ "'")测试了下,确实name有值呀,
    虽然有错误,但提示错误里都有值呀,提示错误如下:
    select * from util where name='aa'  Microsoft VBScript 编译器错误 错误 '800a03f6' 
    缺少 'End' 
    可见name是有值的呀
      

  3.   

    我对ASP不熟悉,记得VB里面的连接字符串的运算符好像是“&”而不是“+”,请确定!
      

  4.   

    vb.net里 "&"和"+"都可以用来连接.
      

  5.   

    Set RSAllFinancialRecord =conn.Execute("select * from util where name='" + name + "'")这样看看吧,要复制我的这句哦。如果不行就再说罗。嘿嘿
      

  6.   

    问题最新进展:
     目前做法是把Response.ContentType = "application/vnd.ms-excel"
    测试时就把这句关闭,
    用Set RSAllFinancialRecord =conn.Execute("select * from util where name='"+ name+ "'")
    能在html显示出来,但不能成功生成到excel中去,
    但如果直接用'Set RSAllFinancialRecord = conn.Execute("select * from util where name = 'aa' ")
    可以写到excel中去,请问什么原因,如何修改?