|
-
Dec 22nd, 1999, 10:41 AM
#1
Thread Starter
New Member
How can I pass a parameter to a stored procedure(the parameter is used in a select query in the procedure). Then run the procedure and notify VB that the procedure completed so VB can do something else.
-
Dec 22nd, 1999, 11:29 AM
#2
Guru
This is a synchronous call to a stored procedure, assuming your parameter is in a textbox (or put a variable where text1.text is) and VB will wait until the stored procedure has completed, and the results will be stored in recordset (RS).
If you want your code to do other things while waiting for completion of the stored procedure, let me know and I will post some code that does an asynchronous call to the db.
Code:
dim rs as adodb.recordset
dim cn as adodb.connection
set cn = new connection
cn.open <connectionstringtodb>
set rs = cn.execute("sp_StoredProcName '" & text1.text & "'",,adcmdtext)
-
Dec 23rd, 1999, 08:30 AM
#3
Thread Starter
New Member
Yes, I do need my code to continue doing other things. I appreciate your knowledge and help.
-
Dec 23rd, 1999, 12:24 PM
#4
Guru
OK
This is the code from a standard form and a single command button. It seems to be more trouble than it's worth (at least for small projects, but what the hell...)
Code:
Option Explicit
Dim WithEvents cn As ADODB.Connection
Dim WithEvents rs As ADODB.Recordset
Dim boolConnectCompleted As Boolean
Private Sub cn_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
boolConnectCompleted = True
End Sub
Private Sub cn_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
MsgBox pRecordset.Fields(0).Value
End Sub
Private Sub Command1_Click()
cn.Open "Provider=SQLOLEDB.1;Data Source=TOM;UID=sa;Initial Catalog=Northwind", , , adAsyncConnect
Do Until boolConnectCompleted = True
DoEvents
Loop
cn.Execute "Select * from Customers", , adCmdText
End Sub
Private Sub Form_Load()
Set cn = New Connection
boolConnectCompleted = False
End Sub
Hope you find that useful
Tom
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|