Forums

ASP

This topic is locked

Keep getting 'Type Mismatch'

Posted 01 Sep 2007 17:14:55
1
has voted
01 Sep 2007 17:14:55 Simon Bloodworth posted:
Hi

im trying to query a recordset within an loop taking the values from an array, but all i keep getting is 'Type Mismatch'

the code is:

Dim SearchString
Dim ItemArray
Dim SearchItem

SearchString = RsEmailer.Fields.Item("E_SearchString".value
ItemArray = Split(SearchString,","

For i = 0 to Ubound(ItemArray)
SearchItem = ""
SearchItem = ItemArray

Dim RsEmailLooper__VarItem
If (SearchItem <> "" Then
RsEmailLooper__VarItem = SearchItem
End If

Dim RsEmailLooper
Dim RsEmailLooper_numRows

Set RsEmailLooper = Server.CreateObject("ADODB.Recordset"
RsEmailLooper.ActiveConnection = MM_BFJ_STRING
RsEmailLooper.Source = "SELECT * FROM tblItemData WHERE I_CATEGORY LIKE '%RsEmailLooper__VarItem%'"
RsEmailLooper.CursorType = 0
RsEmailLooper.CursorLocation = 2
RsEmailLooper.LockType = 1
RsEmailLooper.Open()

RsEmailLooper_numRows = 0
Next


the error is on line 76 which is 'If (SearchItem <> "" Then'

I cant see where the problem is, I wondered if anyone could see any thing

regards

Simon

DWMX 2004 | ASP | VBScript

Replies

Replied 03 Sep 2007 10:41:12
03 Sep 2007 10:41:12 Lee Diggins replied:
Hi Simon

Your query is sending the entire string to SQL like this:

"SELECT * FROM tblItemData WHERE I_CATEGORY LIKE '%RsEmailLooper__VarItem%'"

You need to separate out the sql string from your variable so the variable value is included in the sql string not the name of the variable, like this:

"SELECT * FROM tblItemData WHERE I_CATEGORY LIKE '%" & RsEmailLooper__VarItem & "%'"

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 04 Sep 2007 00:51:18
04 Sep 2007 00:51:18 Simon Bloodworth replied:
thanks lee - think ive got it sussed now

cheers

Simon

DWMX 2004 | ASP | VBScript

Reply to this topic