473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

recordset problem

Hi Guys, me again!!!!

I've got a little recordset problem, basically I'm trying to build a jobs by
email feature, so I have the following -

Jobs by Email table which includes -

category
location
keyword

a form where an advertiser posts their vacancy, the form submits the data to
the database and then passes the data on to the page that processes the jobs
by email query -

currently the recordset for selecting all users with matching jobs by email
notifications looks like this --

<%
Dim jbeusers__MMColParam3
jbeusers__MMColParam3 = "0"
If (Session("SITEID") <"") Then
jbeusers__MMColParam3 = Session("SITEID")
End If
%>
<%
Dim jbeusers__MMColParam
jbeusers__MMColParam = "0"
If (Session("NEWVACANCYLOCATION") <"") Then
jbeusers__MMColParam = Session("NEWVACANCYLOCATION")
End If
%>
<%
Dim jbeusers__MMColParam2
jbeusers__MMColParam2 = "0"
If (Session("NEWVACANCYCATEGORY") <"") Then
jbeusers__MMColParam2 = Session("NEWVACANCYCATEGORY")
End If
%>
<%
Dim jbeusers__MMColParam4
jbeusers__MMColParam4 = "%"
If (Session("NEWVACANCYDESCRIPTION") <"") Then
jbeusers__MMColParam4 = Session("NEWVACANCYDESCRIPTION")
End If
%>
<%
Dim jbeusers
Dim jbeusers_cmd
Dim jbeusers_numRows

Set jbeusers_cmd = Server.CreateObject ("ADODB.Command")
jbeusers_cmd.ActiveConnection = MM_recruta2_STRING
jbeusers_cmd.CommandText = "SELECT JBENusername, JBENPassword, JBENname FROM
dbo.JBEmailNotification WHERE JBENsiteID = ? AND ? = JBENlocation AND ? =
JBENcategory AND JBENKeyword LIKE ?"
jbeusers_cmd.Prepared = true
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param1", 5, 1,
-1, jbeusers__MMColParam3) ' adDouble
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param2", 200,
1, 255, jbeusers__MMColParam) ' adVarChar
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param3", 200,
1, 255, jbeusers__MMColParam2) ' adVarChar
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param4", 200,
1, 255, "%" + jbeusers__MMColParam4 + "%") ' adVarChar

Set jbeusers = jbeusers_cmd.Execute
jbeusers_numRows = 0
%>

this works fine if the variables are -

MMColParam3 = 31
MMColParam = Hereford
MMColParam2 = IT
MMColParam4 = dreamweaver

as I have two records in the jobs by email table that match this criteria...

However as MMColParam4 is the advert description, it would contain more than
just dreamweaverr in it, for instance when i try and use the value "we
urgently require dreamweaver developers"

The recordset returns no records...

effectively what I'm trying to do is filter records where the siteid,
location and category match of the advert and the jobs by email keyword is
contained within the description,..
Anyone got any ideas what I'm doing wrong?

Thank you

Jul 21 '08 #1
12 1788
GTN170777 wrote:
Hi Guys, me again!!!!

I've got a little recordset problem, basically I'm trying to build a
jobs by email feature, so I have the following -

Jobs by Email table which includes -
What database are you using?
>
category
location
keyword

a form where an advertiser posts their vacancy, the form submits the
data to the database and then passes the data on to the page that
processes the jobs by email query -

currently the recordset for selecting all users with matching jobs by
email notifications looks like this --
<snip>
jbeusers_cmd.CommandText = "SELECT JBENusername, JBENPassword,
JBENname FROM dbo.JBEmailNotification WHERE JBENsiteID = ? AND ? =
JBENlocation AND ? = JBENcategory AND JBENKeyword LIKE ?"
<snip>
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param4",
200, 1, ' adVarChar
Well, it appears that what you have done here should work ... you're going
to a little too much trouble (you could use a variant array to pass the
parameter values rather than going to the trouble of building the Parameters
collection) but that should not be causing this symptom.

Try appending the wildcards in your query rather than in the parameter
value:

If Access:
.... JBENKeyword LIKE '%' & ? & '%'"

If SQL Server:
.... JBENKeyword LIKE '%' + ? + '%'"

and change your CreateParameter call to:
255, jbeusers__MMColParam4)
************************************************** ******************************
I'm curious:
why do you write "? = JBENcategory" instead of "JBENcategory = ?"

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 21 '08 #2
Hi Bob,

Just tried changing that, I've put it together as an SP - shown below,

Again the recordset works fine if the description is only dreamweaver, but
if it is for example, we need dreamweaver developers, nothing is returned --

so really what I am trying to do is select a record where the keyword is
contained in the description variuable, as well as the other criteria??

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND JBENcategory =
@category AND JBENKeyword LIKE '%'+'@Description'+'%'
GO

Thanks for your help, any other thoughts would be great?


"Bob Barrows [MVP]" wrote:
GTN170777 wrote:
Hi Guys, me again!!!!

I've got a little recordset problem, basically I'm trying to build a
jobs by email feature, so I have the following -

Jobs by Email table which includes -

What database are you using?

category
location
keyword

a form where an advertiser posts their vacancy, the form submits the
data to the database and then passes the data on to the page that
processes the jobs by email query -

currently the recordset for selecting all users with matching jobs by
email notifications looks like this --
<snip>
jbeusers_cmd.CommandText = "SELECT JBENusername, JBENPassword,
JBENname FROM dbo.JBEmailNotification WHERE JBENsiteID = ? AND ? =
JBENlocation AND ? = JBENcategory AND JBENKeyword LIKE ?"
<snip>
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param4",
200, 1, ' adVarChar
Well, it appears that what you have done here should work ... you're going
to a little too much trouble (you could use a variant array to pass the
parameter values rather than going to the trouble of building the Parameters
collection) but that should not be causing this symptom.

Try appending the wildcards in your query rather than in the parameter
value:

If Access:
.... JBENKeyword LIKE '%' & ? & '%'"

If SQL Server:
.... JBENKeyword LIKE '%' + ? + '%'"

and change your CreateParameter call to:
255, jbeusers__MMColParam4)
************************************************** ******************************
I'm curious:
why do you write "? = JBENcategory" instead of "JBENcategory = ?"

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 21 '08 #3
GTN170777 wrote:
Hi Bob,

Just tried changing that, I've put it together as an SP - shown below,

Again the recordset works fine if the description is only
dreamweaver, but
if it is for example, we need dreamweaver developers, nothing is
returned --

so really what I am trying to do is select a record where the keyword
is contained in the description variuable, as well as the other
criteria??

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND
JBENcategory = @category AND JBENKeyword LIKE '%'+'@Description'+'%'
GO
So this is SQL Server ... what version?
When you run this procedure in Query Analyzer or SSMS, does it return the
correct results? If so, the problem is in the vbscript code.

If not, you need to show me how to reproduce the symptoms. Generate a CREATE
TABLE script for your JBEmailNotification table, create some insert
statements to insert some sample data that I can run, and I will try to
repro this.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 21 '08 #4
Hi Bob,

MS SQL Server 2000,

the DDL for the JBEmailNotification table is

CREATE TABLE [dbo].[JBEmailNotification] (
[JBENotificationID] int IDENTITY(1, 1) NOT NULL,
[JBENsiteID] int NULL,
[JBENlocation] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENcategory] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENname] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENusername] nvarchar(225) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENcandidateID] int NULL,
[JBENPassword] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENDateRegistered] datetime CONSTRAINT [DF__JBEmailNo__JBEND__3FD07829]
DEFAULT convert(char(19),getdate(),120) NULL,
[JBENKeyword] nvarchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [aaaaaJBEmailNotification_PK] PRIMARY KEY NONCLUSTERED
([JBENotificationID])
)
ON [PRIMARY]
GO

Not to sure how to write an insert statement, currently though i just have
one record -

JBENsiteID - 31
JBENlocation = Hereford
JBENcategory = IT
JBENname = Gareth
JBENusername = Ga*********@aol.com
JBENPassword = lorgar
JBENKeyword = dreamweaver

Hope this is of use and you can highlight what I'm doing wrong?

Thanks
"Bob Barrows [MVP]" wrote:
GTN170777 wrote:
Hi Bob,

Just tried changing that, I've put it together as an SP - shown below,

Again the recordset works fine if the description is only
dreamweaver, but
if it is for example, we need dreamweaver developers, nothing is
returned --

so really what I am trying to do is select a record where the keyword
is contained in the description variuable, as well as the other
criteria??

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND
JBENcategory = @category AND JBENKeyword LIKE '%'+'@Description'+'%'
GO

So this is SQL Server ... what version?
When you run this procedure in Query Analyzer or SSMS, does it return the
correct results? If so, the problem is in the vbscript code.

If not, you need to show me how to reproduce the symptoms. Generate a CREATE
TABLE script for your JBEmailNotification table, create some insert
statements to insert some sample data that I can run, and I will try to
repro this.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 21 '08 #5
GTN170777 wrote:
Hi Bob,

MS SQL Server 2000,

the DDL for the JBEmailNotification table is

CREATE TABLE [dbo].[JBEmailNotification] (
[JBENotificationID] int IDENTITY(1, 1) NOT NULL,
[JBENsiteID] int NULL,
[JBENlocation] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL, [JBENcategory] nvarchar(50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL, [JBENname] nvarchar(50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL, [JBENusername] nvarchar(225)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JBENcandidateID] int
NULL, [JBENPassword] nvarchar(50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL, [JBENDateRegistered] datetime
CONSTRAINT [DF__JBEmailNo__JBEND__3FD07829] DEFAULT
convert(char(19),getdate(),120) NULL, [JBENKeyword] nvarchar(100)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL, CONSTRAINT
[aaaaaJBEmailNotification_PK] PRIMARY KEY NONCLUSTERED
([JBENotificationID]) )
ON [PRIMARY]
GO

Not to sure how to write an insert statement,
For future reference:
INsert tablename (columns)
VALUES (<list of hard-coded values>)

There are tools to enable these statements to be generated, including this
code from Vyas:
http://vyaskn.tripod.com/code.htm#inserts

currently though i just
have one record -

JBENsiteID - 31
JBENlocation = Hereford
JBENcategory = IT
JBENname = Gareth
JBENusername = Ga*********@aol.com
JBENPassword = lorgar
JBENKeyword = dreamweaver
I just spotted your problem: you enclosed the @description parameter in
quotes:
AND JBENKeyword LIKE '%'+'@Description'+'%'

'@description' does not exist in your data, correct? it should of course be
AND JBENKeyword LIKE '%'+@Description+'%'

UPDATE dbo.JBEmailNotification
SET JBENKeyword = 'dreamweaver'
exec TEST 31,'dreamweaver','Hereford','IT'
UPDATE dbo.JBEmailNotification
SET JBENKeyword = 'dreamweaver engineer'
exec TEST 31,'dreamweaver','Hereford','IT'

The above script returns the correct results for me.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 21 '08 #6
I don't think Bob Barrows has completely diagnosed your problem.

He is patently correct about getting rid of the '...' around '@description',
but I think that's just part of the problem.

Let's consider what happens when you use
WHERE ...JBENKeyword LIKE '%'+@Description+'%'
and then pass in an @Description value such as
'we need dreamweaver developers'

Okay, so AFTER the substitution, you will be doing
WHERE ...JBENKeyword LIKE '%we need dreamweaver developers%'

And if you have *ONLY* the one record with the value
JBENKeyword = 'dreamweaver'
then you are essentially trying to do
WHERE ...'dreamweaver' LIKE '%we need dreamweaver developers%'

Guess what? You ain't never gonna find no match on that!!!!

*NOW* try doing
WHERE ...'we need dreamweaver developers' LIKE '%' + JBENKeyword + '%'

You see it?

If not, look here:
http://msdn.microsoft.com/en-us/libr...2(SQL.80).aspx

Jul 21 '08 #7
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'

Remember. the '%' character when used with LIKE means "and any number of
other characters". So '%Dreamweaver%' means '[any
stuff]Dreamwearver[anystuff]'.

Caution: This still isn't going to find a description such as
'we need dream weaver developers'
(note the space between 'dream' and 'weaver')

Since you are using SQL Server, perhaps you would want to consider full text
searching, and then allowing your job postings to have nice long keyword
strings with every possibly fun matching keyword in them?
Jul 21 '08 #8
Hi Both, Thanks for your help so far, I am sadly still having major problems
and can't get it to return any records now...

I've tried the below but get nothing

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND JBENcategory =
@category AND @Description LIKE '%+JBENKeyword%'

When i tried @Description LIKE '%'+JBENKeyword'%' I got a Incorrect syntax
near '%'. error message

??

"Old Pedant" wrote:
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'

Remember. the '%' character when used with LIKE means "and any number of
other characters". So '%Dreamweaver%' means '[any
stuff]Dreamwearver[anystuff]'.

Caution: This still isn't going to find a description such as
'we need dream weaver developers'
(note the space between 'dream' and 'weaver')

Since you are using SQL Server, perhaps you would want to consider full text
searching, and then allowing your job postings to have nice long keyword
strings with every possibly fun matching keyword in them?

Jul 22 '08 #9
GTN170777 wrote:
Hi Both, Thanks for your help so far, I am sadly still having major
problems and can't get it to return any records now...

I've tried the below but get nothing

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND
JBENcategory = @category AND @Description LIKE '%+JBENKeyword%'

When i tried @Description LIKE '%'+JBENKeyword'%' I got a Incorrect
syntax near '%'. error message
That's because it should have said this:

@Description LIKE '%' & JBENKeyword & '%'
(I tend to use & for concatenation to avoid unexpected results)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '08 #10
"Bob Barrows [MVP]" wrote:
That's because it should have said this:

@Description LIKE '%' & JBENKeyword & '%'
(I tend to use & for concatenation to avoid unexpected results)
Well, yes, you SHOULD use & for concatenation in VBScript and VB and even
Access SQL.

BUT *NEVER NEVER* in SQL Server! GTN even said so.

For SQL Server, look here:
http://msdn.microsoft.com/en-us/libr...6(SQL.80).aspx

The & operator in T-SQL is *ONLY* used to mean bit-wise anding.

You *MUST* use + for string concatenation in T-SQL. Period.

And this *IS* SQL Server 2000.

And
Jul 22 '08 #11
*I* wrote:
*NOW* try doing
WHERE ...'we need dreamweaver developers' LIKE '%' + JBENKeyword + '%'
*YOU* coded
... AND @Description LIKE '%+JBENKeyword%'
Those two are not even *CLOSE* to this same thing.

Yes, the second time I posted I typoed and left out the + operator when I
wrote
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'
Clearly that should have been
WHERE ... @Description LIKE '%' + JBENKeyword + '%'
We are trying to BUILD UP a string that has the keyword in the middle and a
% character on each end. And the only good way to do that in SQL Server
(T-SQL, same thing) is to use the + operator.
Jul 22 '08 #12
Thanks Old Pedant, works a treat (sorry for the late responce - had a cold)
I'm hoping to get on an MS SQL course, am UK based, can you recommend any?

Again thanks for your help

GTN

"Old Pedant" wrote:
*I* wrote:
*NOW* try doing
WHERE ...'we need dreamweaver developers' LIKE '%' + JBENKeyword + '%'

*YOU* coded
... AND @Description LIKE '%+JBENKeyword%'

Those two are not even *CLOSE* to this same thing.

Yes, the second time I posted I typoed and left out the + operator when I
wrote
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'

Clearly that should have been
WHERE ... @Description LIKE '%' + JBENKeyword + '%'

We are trying to BUILD UP a string that has the keyword in the middle and a
% character on each end. And the only good way to do that in SQL Server
(T-SQL, same thing) is to use the + operator.

Jul 24 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dima Protchenko | last post by:
Hi, guys. Please help if you know something about this. Error: ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed. line: if not rs.EOF then (from the code...
5
by: Tom van Stiphout | last post by:
Hi all, I'm seeing a weird problem I'm thinking might be due to corruption. What do you think? Here is the relevant code, which is in a standard module, called from subfrmDetail's...
3
by: | last post by:
Hello ppl, I have snippet that works fine udner ADODB with VB6, but something wrong with it in Vb.NET. Anyone can help? Recordset1 (ADODB.Recordset) Error: Arguments are of the wrong type, are...
10
by: LucaBrasi | last post by:
I am using a DAO recordset based on a table on the back end, and the table has almost 11,000 rows. Is there a way to 'filter' the table to use only the rows that meet my criteria ? I know I could...
2
by: Bobby | last post by:
Hello, I have an application which uses a SQL server 2003 Back end and an Access 2003 front end. I am trying to populate a recordset in the FE with data from an ODBC linked table to the BE....
1
by: CJD | last post by:
Hi, I have a set of queries in access that I would like to import into excel. My problem is that there are no records are returned when the code is run, but I do get field names. This same code...
0
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
3
by: Dilruba | last post by:
I want to create a Recordset and after that start a loop and within that loop i am creating more other recordset. But Recordset within the loop is not working properly i.e. they are not getting...
2
by: paulquinlan100 | last post by:
Hi I'm using the following code to retrieve some data from a seperate DB: Dim con As New ADODB.Connection con.Open _ "Provider=Microsoft.jet.oledb.4.0; Data Source=\...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.