SunQuest
 
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old November 22nd, 2004, 07:21 AM
Graham Reeds Graham Reeds is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 28 Graham Reeds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 36 m 24 sec
Reputation Power: 0
Executing an SQL with a Long in it.

I'm having a bit of bother with some of my code, also this concerns ASP, VB, and SQL so I thought since it is mainly a VB problem I'd post it in the VB forum.

I have an ASP page that determines whether you are wishing to search by Name or Company.
The FindByX functions are in a DLL and are exactly the same except the variables that are passed are a String for the name (like "John Doe") or a Long (like "5") and the SQL for the search.

Here's the code that I use for determining which to use:

PHP Code:
 Dim ObjRS
        Set Obj 
Server.CreateObject("Enterprise_DAL.Employee")
        If 
Request.Form("SearchMethod")="E" Then
            Set RS 
Obj.FindByName(Request.Form("SearchName"))
        Else
            
Set RS Obj.FindByCompanyID(Request.Form("SelectCompany"))
        
End If 


And the code for the FindByCompanyID - remember that FindByName is exactly the same except for the SQL and parameters.

PHP Code:
' Find By Company
Public Function FindByCompanyID(CompanyID As Long) As ADODB.Recordset
    Dim Conn As ADODB.Connection
    Dim RS As ADODB.Recordset
    Dim SQL
    ' 
Create and set the connection information.
    
Set Conn CreateObject("ADODB.Connection")
    
Conn.ConnectionString "Provider=MSDASQL; DSN=TestDatabase;"
    
Conn.Open

    
' Build the SQL string
    SQL = "SELECT * FROM Employee WHERE CompanyID=" + CompanyID

    ' 
Create and set the recordset information
    Set RS 
CreateObject("ADODB.Recordset")
    
RS.ActiveConnection Conn
    RS
.CursorLocation adUseClient
    RS
.Source SQL
    RS
.Open SQL, , adOpenForwardOnlyadLockReadOnly
    Set FindByCompanyID 
RS

    
' Close everything down
    RS.ActiveConnection = Nothing
    Conn.Close
    Set Conn = Nothing
End Function 


However it doesn't work.
As it stands it returns an "Object variable or With block variable not set" error on Line 74 of the ASP.

A quick search on Google reveals that this occurs if: "You define a public variable in the COM component" and "The variable is of the Object type" and "You reference this COM component by using late binding."

Okay, my VB skills aren't that 1337 but I do know this: There are no public variables in my DLL. There are 3 methods and no properties (this is a simple test case to prove I can do what the prospective employer asks). The variable is of object type and I do bind it late. Switching to early binding does nothing to remedy the situation.

So I thought it might be that I might be passing it as a String to the function. So I wrap the parameter with a CInt() so the line becomes:

PHP Code:
 Set RS Obj.FindByCompanyID(CInt(Request.Form("SelectCompany"))) 
This gives me the same "Object variable or With block variable not set" that I had before. Okay, so the ASP isn't broken - must be something to do with the VB code.

Let's look at the function: All variables are Dim'd to begin with so that isn't it. Both early and late binding doesn't change anything. Numbers aren't wrapped by quotes when writing SQL statements but - hey - I'm stuck so I will change it. Still nothing.

So I am stuck and ask why is this? Is it my ASP or VB? Also I am not allowed to change the parameters.

If you want/need more information don't hesitate to ask.
Thanks, G.

Reply With Quote
  #2  
Old November 22nd, 2004, 09:13 AM
Graham Reeds Graham Reeds is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 28 Graham Reeds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 36 m 24 sec
Reputation Power: 0
I converted the CompanyID from a Long to a String and added the additional single quote to encase the string and it works fine. However the specs require it to be a Long.

Therefore I can safely (99.9%) assume that it is something to do with my VB function. But what?

Thanks.

Edit: Just realised that if it works as a string then CompanyID must be a string in the database. However I have it open in front of me and it is most definately not. An Int with a precision of 4.

Reply With Quote
  #3  
Old November 22nd, 2004, 02:54 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
Try using & for concatenation in your code, instead of +
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #4  
Old November 22nd, 2004, 09:08 PM
Graham Reeds Graham Reeds is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 28 Graham Reeds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 36 m 24 sec
Reputation Power: 0
Thanks - that works. Now that raises a couple of questions:

Firstly why would it work with the string as + but with numbers with &?

Secondly when I was using strings didn't SQL Server fire off an error telling me I am trying to insert a string into a number (or why did it convert it)?

Thanks for your help. On to the next problem(s):-)

Reply With Quote
  #5  
Old November 23rd, 2004, 01:31 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
The + operator will try to do math on the values before concatenating, where the & is only a string concatenation operator.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Executing an SQL with a Long in it.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway