使用 VBscript 从 SQL 数据库中读取数据 [英] Using VBscript to read from an SQL database

查看:27
本文介绍了使用 VBscript 从 SQL 数据库中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个 SQL 数据库,我想在其中使用 vbscript 从中读取数据.

I have an SQL database set up in which I would like to use a vbscript to read from it.

这是我尝试使用的代码.

Here is the code I am trying to use.

    SQL_Command_String = "SELECT * FROM Table1 JOIN Table2 WHERE Table1.ID = '5' AND Table2.Date LIKE '2011'"

Set Rs = SQLConnection.Execute(SQL_Command_String)
 DO WHILE NOT Rs.EOF
file1="./seminars/"&seminar_type&"/"&seminar_year&"/"&Rs("date")&"-"&Rs("year")&"_"&Rs("last")&".pdf"

seminar_year 和seminar_type 是我已经初始化并声明为seminar_year = 2011 和seminar_type = section1 的常量.

seminar_year and seminar_type are constants I have initialized and declared to be seminar_year = 2011 and seminar_type = section1.

我相信我把 SQL_Command_String 与 LIKE 语句搞混了.我不确定它是否被正确使用.我只是想让它找到日期中包含 2011 年的单元格,但我不确定是否应该包含日期的月份和日期部分的通配符,如果是这样,通配符是什么?

I believe I have the SQL_Command_String messed up with the LIKE statement. I'm not sure if it is being used properly. I just want it to find cells that include 2011 in the date but i'm not sure if I should include wildcards for the month and day portions of the date and if so what wildcards?

当我注释掉 Rs 的声明 (Set) 时,页面加载正常(除了它没有填写表格).包含时显示的错误是处理URL时服务器发生错误.请联系系统管理员.如果您是系统管理员,请单击此处了解有关此错误的更多信息."

When I comment out the declaration (Set) of Rs the page loads fine (except that it hasn't filled out the table). The error that is displayed when included is "An error occurred on the server when processing the URL. Please contact the system administrator. If you are the system administrator please click here to find out more about this error. "

这里只是简单地将您带到一个关于运行 os IIS 7 的微软页面,我已经考虑过了.

The here simply takes you to a microsoft page about running os IIS 7 which I have already accounted for.

我真的被这个问题难住了,我的想法是我的 SQL 命令不正确,与新框架存在冲突,或者我没有正确声明读者,或者我没有使用正确的读者类型.

I'm really stumped on this one my thoughts are I have the SQL command incorrect, there is a confliction with the new framework that is out, or I am not declaring the reader correctly or perhaps i'm not using the correct type of reader.

我非常感谢 SO 社区的任何见解.谢谢,请知道我是 VBscripts 的新手

I would appreciate any insights the SO community has. Thanks and please know I am very new at VBscripts

推荐答案

尝试删除 AND Table2.Date LIKE '2011' 部分,看看它是否有效.我猜这是因为您的日期列是日期或日期时间数据类型,而不是字符类型.我认为 LIKE 仅适用于 char 数据类型,因此您需要进行实际日期比较,例如Table2.Date >= '1/1/2011' AND Table2.Date <='12/31/2011' 或类似的东西,具体取决于您使用的数据库.

Try removing the AND Table2.Date LIKE '2011' part and see if it works. I'm guessing it's because your date column is a date or datetime data type as opposed to char type. I think LIKE will only work for char data types, so you will need to do an actual date comparison e.g. Table2.Date >= '1/1/2011' AND Table2.Date <= '12/31/2011' or something similar, depending on the database your using.

这篇关于使用 VBscript 从 SQL 数据库中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆