Solved

SQL question

Posted on 2002-05-03
11
157 Views
Last Modified: 2010-05-02
hi can someone please tell me why this statement will not work it works fine when just searching for subdom but will not when using AND Please advise...

Subdom = Request.QueryString("Subdom")
Domain = Request.QueryString("Domain")
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

   ' Open the connection
   cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & App.Path & "\DDNSHCP.mdb;"
 
   ' Open the recordset
   rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = "' & Domain & "'", _
      cnn, adOpenKeyset, adLockOptimistic
0
Comment
Question by:hilltop
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 2

Author Comment

by:hilltop
ID: 6989522
This is being executed from a webclass
0
 
LVL 12

Expert Comment

by:roverm
ID: 6989641
Couple of possibilities:
1. Make sure the query isn't case sensitive:
SELECT * FROM Users WHERE UCase(Subdom) = '" & UCase(Subdom) & "' AND UCase(Domain) = "' & UCase(Domain) & "'" (I am not sure about the UCase in the SQL statement, could be Upper as well).
2. Use the LIKE statement instead of the '=':
SELECT * FROM Users WHERE Subdom LIKE '" & Subdom & "%' AND Domain LIKE "' & Domain & "%'" (make sure to add the percent sign '%')
3. Combine the first 2 options.

D'Mzzl!
RoverM  
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6989671
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = "' & Domain & "'", _
     cnn, adOpenKeyset, adLockOptimistic

Unless it is a typo you have the quotes backwards between Domain = and & Domain

Should be
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = '" & Domain & "'", _
     cnn, adOpenKeyset, adLockOptimistic

If that is not the problem what error are you getting?  

If you are just not getting any records are you sure records exist for the criteria?

good luck
mlmcc
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 2

Author Comment

by:hilltop
ID: 6989882
No dice when using
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "' AND Domain = '" & Domain & "'", _
    cnn, adOpenKeyset, adLockOptimistic

It just pops up the microsoft script debugger no error other than that.

when using
rst.Open "SELECT * FROM Users WHERE Subdom = '" & Subdom & "'", _
      'cnn, adOpenKeyset, adLockOptimistic

it works fine I am at a serios loss here
0
 
LVL 2

Author Comment

by:hilltop
ID: 6989886
new development when using

rst.Open "SELECT * FROM Users WHERE Domain = '" & Domain & "'", _
      cnn, adOpenKeyset, adLockOptimistic

it errors as well this is a field in the Users table any ideas
0
 
LVL 2

Author Comment

by:hilltop
ID: 6989998
I renamed the field Domains and updated my app to reflect the new field name were applicable the AND statment now works fine. Do you have any idea why this happened
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 6990453
Domain is a reserved word.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6990460
You could also have surrounded with square brackets [Domain]
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6992705
You're right emoreau.  Seems like we overlook the obvious.

mlmcc
0
 
LVL 12

Expert Comment

by:roverm
ID: 6993088
Yeppers....Good one emoreau!
0
 
LVL 2

Author Comment

by:hilltop
ID: 6994098
Thank you very much
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question