rito1
asked on
Example Of Database Connection using ADO Parameters
Hi All
Please could someone provide me with an example ASP database connection string to a SQL Server 2000 database and 1 ADO parameter which loads the data into a recordset.
Many thanks,
Rit
Please could someone provide me with an example ASP database connection string to a SQL Server 2000 database and 1 ADO parameter which loads the data into a recordset.
Many thanks,
Rit
ASKER
Hi angellll,
The parameters need to be passed into a stored procedure and also 1 minor detail I missed was - I am using VBScript.. Sorry!
Rit
The parameters need to be passed into a stored procedure and also 1 minor detail I missed was - I am using VBScript.. Sorry!
Rit
i dont do it that way i use this way
Set DBatd = Server.CreateObject("ADODB.Connection")
DBcon.Open "Provider=SQLOLEDB; Server=192.168.1.1; Database=database name; UID=userid; PWD=password;"
Set Results = DBCon.Execute("select * from table1")
ops line 1 should be Set DBcon
ASKER
Hi,
The reason I was doing it with parameters was that I have been stunk by an SQL injection attack previous so wanted to use ADO parameters to declare them.
Here is the code I have so far... I just can't figure out how to load the data into a recordset:
Set cn = Server.CreateObject("ADODB .Connectio n")
cn.Open strDSNless
Set cmd = Server.CreateObject("ADODB .Command")
Set cmd.ActiveConnection = cn
cmd.CommandText = "sp_SELECTCustomers"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("Param 1", adInteger, _
adParamInput)
' Set value of Param1 of the default collection to 22
cmd("Param1") = 22
cmd.Execute
The reason I was doing it with parameters was that I have been stunk by an SQL injection attack previous so wanted to use ADO parameters to declare them.
Here is the code I have so far... I just can't figure out how to load the data into a recordset:
Set cn = Server.CreateObject("ADODB
cn.Open strDSNless
Set cmd = Server.CreateObject("ADODB
Set cmd.ActiveConnection = cn
cmd.CommandText = "sp_SELECTCustomers"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("Param
adParamInput)
' Set value of Param1 of the default collection to 22
cmd("Param1") = 22
cmd.Execute
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.asp.happycodings.com/DataAccess/code8.html