Article ID: 170147
Article Last Modified on 7/1/2004
Create Table IColTest
(Id_Col int Identity, F2 VarChar(30) Null)
Create Unique Index IIndex on IColTest(Id_Col)
Create Procedure MyInsert
@FieldVal Varchar(30), @id Int OUTPUT AS
Insert Into IColTest (F2) Values(@FieldVal)
Select @id = @@Identity
Private Sub Command1_Click()
Dim cn As New rdoConnection
Dim qy As New rdoQuery
Dim strConnect As String
strConnect = "Driver={SQL Server}; Server=MyServer; _
Database=Pubs; Uid=<username>; Pwd=<strong password>"
With cn
.Connect = strConnect
.LoginTimeout = 5
.EstablishConnection rdDriverNoPrompt, True
End With
With qy
Set .ActiveConnection = cn
.SQL = "{Call MyInsert(?, ?)}"
End With
qy(0).Direction = rdParamInput
qy(1).Direction = rdParamOutput
qy(0) = "RainBow"
qy.Execute
Debug.Print qy(1)
End Sub
In Visual Basic 5.0 and higher, you can also use the User Connection
Designer (CQD) to create rdoQuery objects in your project. The CQD takes your
SQL query and permits you to specify the data types for each parameter. It then
inserts appropriate code in your application to expose these procedures very
much like methods off the rdoQuery object.
Private Sub Command2_Click()
Dim cn As New rdoConnection
Dim rs As rdoResultset
Dim strConnect as string
strConnect = "Driver={SQL Server}; Server=MyServer; _
Database=Pubs; Uid=<username>; Pwd=<strong password>"
With cn
.Connect = strConnect
.LoginTimeout = 5
.EstablishConnection rdDriverNoPrompt, True
End With
Set rs = cn.OpenResultset _
("SET NOCOUNT ON _
INSERT INTO IColTest(F2) VALUES('Balloon') _
SELECT @@IDENTITY _
SET NOCOUNT OFF")
Debug.Print rs(0)
rs.Close
cn.Close
End Sub
166281 : How To Create and Implement a UserConnection
Additional query words: kbVBp400 kbVBp600 kbdse kbDSupport kbVBp kbRDO
Keywords: kbhowto KB170147