注册 登录
编程论坛 ASP技术论坛

ASP查询EXCEL,请问!

kaibinchao 发布于 2009-09-17 21:55, 866 次点击
大家好,我想在ASP中查询EXCEL表里日期为#2009-1-1# and #2009-9-17#的记录,EXCEL里日期列已经设置为日期yyyy-mm-dd了,数据也都是2009-08-06格式的,用以下两句都查不到任何记录

1、sql="Select * from [Sheet0$] where 日期 between #2009-1-1# and #2009-9-17#"
2、sql="Select * from [Sheet0$] where 日期 between '2009-1-1' and '2009-9-17'"


请问上面两句有问题吗,具体应该怎么查?

用Select * from [Sheet0$]是可以查到全部记录的

表格式:
日期    会员编码    上次余额    入金    出金    本次余额    可用资金    可出资金    转让价差    订货盈亏    订单保证金    交易手续费    结算准备金    交收货款    冻结货款    竞卖保证金    竞买保证金    现货保证金
2009-8-10    85000000    2856.35    0    0    2856.35    228.35    228.35    0    -1390    1238    0    0    0    0    0    0    0



先谢了!
1 回复
#2
aspic2009-09-18 09:04
程序代码:
<%
'读excel文件到数据库
Set Conn = Server.CreateObject("Adodb.Connection")  
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "&Server.Mappath("test.xls")&"; Extended Properties = Excel 8.0"
Conn.Open strConn
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>Excel导入到Access</title>
<style type="text/css">
*{margin:0; padding:0; font-size:12px; color:#444}
table,table th,table td{border-collapse:collapse; border:1px solid #ccc; line-height:24px; text-align:center; color:#515151}
table th{color:#f60}
</style>
</head>
 
<body>
<table cellpadding="0" cellspacing="0" width="500" align="center">
    <tr>
        <th>编号</th>
        <th>名称</th>
        <th>其他</th>
        <th>日期</th>
    </tr>
    <%
    Set Rs = Conn.ExeCute("Select * From [Sheet0$] Where [日期] Between #2009-9-1# and #2009-9-5#")
    Do While Not Rs.Eof
    %>
    <tr>
        <td><%=Rs(0)%></td>
        <td><%=Rs(1)%></td>
        <td><%=Rs(2)%></td>
        <td><%=Rs(3)%></td>
    </tr>
    <%
    Rs.MoveNext
    Loop
    Rs.Close
    Set Rs = Nothing
    %>
</table>
</body>
</html>
表数据
编号    名称    其他    日期
1    名称一    其他一    2009-9-1
2    名称一    其他一    2009-9-2
3    名称一    其他一    2009-9-3
4    名称一    其他一    2009-9-4
5    名称一    其他一    2009-9-5
6    名称一    其他一    2009-9-6
7    名称一    其他一    2009-9-7
8    名称一    其他一    2009-9-8
9    名称一    其他一    2009-9-9
10    名称一    其他一    2009-9-10
11    名称一    其他一    2009-9-11
12    名称一    其他一    2009-9-12
13    名称一    其他一    2009-9-13
1