Microsoft SQL Users.

Status
Not open for further replies.

E3

Ars Centurion
387
rsUsers.Open "select * from bidders",Conn,adOpenForwardOnly,adLockOptimistic <-Line 40 :confused: rsUsers.Filter = "biddername = '" & asd & "'"
'rsUsers.Filter = "biddername = '" & Request.Form("UserName") & "'"

If rsUsers.EOF Then
set rsMaxID = Conn.Execute("SELECT max(bidderid)+1 as maxid from bidders")
dummy1 = rsMaxID("maxid")
set dummy2 =Conn.Execute("Insert into bidders(bidderid) values(" & dummy1 & ")")
'rsUsers.AddNew
End if

rsUsers("biddername")= Request.Form("UserName")
rsUsers("password")= Request.Form("Password")
rsUsers("emailaddress")= Request.Form("Email")
rsUsers("address")= Request.Form("Address")
rsUsers("csz")= Request.Form("Country")
rsUsers("phonenumber")= Request.Form("PhoneNO")
rsUsers("Active") = true
rsUsers("LastLogin")= Now


Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/AddUser.asp, line 40


Line 40 is the same line after the
 

HitScan

Ars Tribunus Militum
2,523
Subscriptor++
To get a whole table by just using it's name you have to use an ADODB.Command object. I never liked them much because I prefer just using SQL with connections or recordets. (however, you'll be getting friendly with Commands if you do ADO.Net stuff later)

As for the latest problem, I'd try to double check the code path and object creation of everything happening before that. Make sure you have an <% Option Explicit %> at the top of your page so you can catch stray variable inits. That can cause many a problem.

HitScan
 

HL7

Ars Praefectus
3,523
Subscriptor++
Originally posted by E3:
If rsUsers.EOF Then
set rsMaxID = Conn.Execute("SELECT max(bidderid)+1 as maxid from bidders")
dummy1 = rsMaxID("maxid")
set dummy2 =Conn.Execute("Insert into bidders(bidderid) values(" & dummy1 & ")")
'rsUsers.AddNew
End if

This is unrelated to your question and I hate to nitpick, but this key-generation logic should occur on the database server with proper error handling to handle concurrency. Also, MAX(bidderid) become quite expensive performance-wise if there are a lot of records. It's OK if the table might include just a few records, but if it's going to include a lot, create a new table that contains the last used ID, and simply retrieve and increment that.

Also, in general, try to avoid retrieving entire tables unless absolutely necessary (it causes a lot of network traffic). Have the user limit the data before it's retrieved, if possible.

Personally, I wrap everything in a stored procedure and then use ADODB.Command to retrieve the data. You can also use ADODB.Command to execute SQL text, which is probably the best way to go about doing what you're trying to do. If you're interested (this include a lot of extra class-related stuff you may not be interested in), here's an example:

code:<HR>
Code:
Public Function GetEmployeeTBTests(ByVal EmployeeID As Long) As colTBTests
    On Error GoTo ErrorHandler
    
    Dim spGetEmployeeTBTests As ADODB.Command
    Dim rsTBTests As ADODB.Recordset
    Dim objTBTest As clsTBTest
    Dim objParam As ADODB.Parameter
    Dim TBTestCollection As colTBTests
    
    Call CheckConnection
    
    Set spGetEmployeeTBTests = New ADODB.Command
    Set spGetEmployeeTBTests.ActiveConnection = mConnection
    
    Set objParam = spGetEmployeeTBTests.CreateParameter("EmployeeID", adInteger, adParamInput, , EmployeeID)
    spGetEmployeeTBTests.Parameters.Append objParam
    
    spGetEmployeeTBTests.CommandText = "GetEmployeeTBTests"
    spGetEmployeeTBTests.CommandType = adCmdStoredProc
    Set rsTBTests = spGetEmployeeTBTests.Execute
    
    Set TBTestCollection = New colTBTests
    
    Do Until rsTBTests.EOF
        Set objTBTest = TBTestCollection.Add("K" & Trim(Str(rsTBTests("EHRecordID"))))
        With objTBTest
            .IsLoading = True
            ' Load Universal Data
            .EHRecordID = rsTBTests("EHRecordID")
            .EmployeeID = EmployeeID
            .DueDate = rsTBTests("DueDate")
            .TBTestTypeID = rsTBTests("TBTestTypeID")
            .ShortName = rsTBTests("ShortName")
            .TBExposureID = rsTBTests("TBExposureID")
            .FollowupTo = rsTBTests("FollowupTo")
            .IsNoticeSent = rsTBTests("IsNoticeSent")
            .TestDate = rsTBTests("TestDate")
            .IsTestRead = rsTBTests("IsTestRead")
            .IsTestPositive = rsTBTests("IsTestPositive")
            .Positivemm = rsTBTests("Positivemm")
            .Comments = rsTBTests("Comments")
            .IsLoading = False
        End With
        rsTBTests.MoveNext
    Loop
    
    rsTBTests.Close
    
    Set objParam = Nothing
    Set objTBTest = Nothing
    Set rsTBTests = Nothing
    Set spGetEmployeeTBTests = Nothing
    Set GetEmployeeTBTests = TBTestCollection
    Set TBTestCollection = Nothing
    
    Call CheckErrors
    
    Exit Function
    
ErrorHandler:
    GenericErrorHandler "GetEmployeeTBTests"
End Function
 

E3

Ars Centurion
387
<%

Dim AccessConnect

' 1. Create an ADO database connection
Set conn = CreateObject("ADODB.Connection")

' 2. Initialise parameters for connection
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=Classified.mdb;" & _
"DefaultDir= c:\Inetpub\wwwroot;" & _
"Uid=Admin;Pwd=;"

' 3. Open using DSNless connection
conn.Open AccessConnect



If Session("bValidUser") = True and Session("PersonID")= "" Then
Dim rsPersonIDCheck
set rsPersonIDCheck = Server.CreateObject("ADODB.Recordset")
Dim strSQL
strSQL = "Select PersonID FROM Person Where EmailAddress = '" & Session("EmailAddress") & "';"

Response.Write strSQL

rsPersonIDCheck.Open strSQL,conn


If rsPersonIDCheck.EOF Then
Session("bValidUser") = false

Else
Session("bidderid") = rsPersonIDCheck("bidderid")
End If
rsPersonIDCheck.Close
End If
%>

<%
Dim rsUsers
set rsUsers = Server.CreateObject ("ADODB.Recordset")
'rsUsers.Open "select * from Person",Conn,adOpenForwardOnly,adLockOptimistic,ad
rsUsers.Open "Person", Conn, adOpenForwardOnly, adLockOptimistic,
adCmdTable
rsUsers.Filter = "EmailAddress = '" & Request.Form("email") & "'"


if rsUsers.EOF then
rsUsers.AddNew
end if

rsUsers("SurName")= Request.Form("LastName")
rsUsers("FirstName")= Request.Form("FirstName")
rsUsers("EmailAddress")= Request.Form("email")
rsUsers("Password")= Request.Form("password")
rsUsers("StreetAddress1")= Request.Form("Address1")
rsUsers("StreetAddress2")= Request.Form("Address2")
rsUsers("City")= Request.Form("City")
rsUsers("State")= Request.Form("State")
rsUsers("PostalCode")= Request.Form("PostalCode")
rsUsers("Country")= Request.Form("Country")
rsUsers("Active") = True
rsUsers("LastLogin")= Now

rsUsers.Update

Dim strName,value
For each sField In rsUsers.Fields
strName = sField.value
value = sField.value
Session(strName)= value
Next
Session("bValidUser") = True
Response.redirect "registerMenu.asp"
%>


Hitscan,Do u mean instead of a recordset , i create a commands object?
set rsUsers = Server.CreateObject ("ADODB.Command")?

The section of codes is taken from an asp book.
Perhaps theres a mistake for that line?
I ve check from the publisher erata list and its not menstioned.

Just plain upset now that i can't do anything about it
 

HitScan

Ars Tribunus Militum
2,523
Subscriptor++
Well, don't try to use what I said just yet. I thought you were writing something up on your own, in which case the only way to get a whole table returned it's name instead of a SQL string is using a command. But if you're using thigns out of a book, don't do what I said because it will only be a confusing mess. :)
Chances are there's a syntax error in the book or your code when you typed it out from the book. I am well aware that some books have terrible terrible code in them. I remember buying a Beginning VC++ book where I basically had to debug all the examples and learning MFC on my own so I could fix what was in the book. :mad: If nothing out of your book seems to work, I'd suggest looking for a better one, there are some duds out there.

HitScan
 

Coleman

Ars Legatus Legionis
16,790
Subscriptor
What he means is that you are only using a very small portion of the ADO framework.

One thing that could be causing your errors, did you include a file to define the enumerations? I'm not sure if you can use the enumerations under ASP without explicitly declaring them or having an include that declares them.

As for the command object, a quick over view for you.
When you are using ADO to connect to a database you really are doing it through a set of 3 objects(even if you don't create the other two, they are created implicitly).

What I would call the bottom-most layer, that is, closest to the database, is a connection object. Next up, is the command object, and then the recordset object.

I don't want to get overly in-depth(read MSDN's ADO stuff, I think it's pretty decent), but one of the things the command object has is a property commandtype. You it has SQL, stored procedure, unknown and a table setting. So you can do:
code:<HR>
Code:
Set myConn = Server.CreateObject("ADODB.Connection")
Set myCmd = Server.CreateObject("ADODB.Command")
Set myRS = Server.CreateObject("ADODB.Recordset")

myConn.Open ' omitting all the specifics

Set myCmd.ActiveConnection = myConn
myCmd.CommandType = 2 'table, enumeration is adCmdTable
myCmd.CommandText = "myTableHere"

Set myRS.Source = myCmd
myRS.Open

That should open a table for you as you requested...that's just off the top of my head so I may have missed a line or two in configuring the recordset object. Anyway, I think the only time you'd really want to open a table like that is to use recordset .AddNew methods. Otherwise you are better off using SQL statements or stored procedures for data retrieval.

-Jason
 
Status
Not open for further replies.