You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example demonstrates using the Refresh method to refresh the Parameters collection for a stored procedure Command object.
'BeginRefreshVB PublicSubMain()OnErrorGoToErrorHandler'To integrate this code 'replace the data source and initial catalog values 'in the connection strings ' connection and recordset variables DimCnxnAsADODB.ConnectionDimcmdByRoyaltyAsADODB.CommandDimrstByRoyaltyAsADODB.RecordsetDimrstAuthorsAsADODB.RecordsetDimstrCnxnAsStringDimstrSQLAuthorsAsString' record variables DimintRoyaltyAsIntegerDimstrAuthorIDAsStringDimstrRoyaltyAsString' Open connection SetCnxn=NewADODB.ConnectionstrCnxn="Provider='sqloledb';Data Source='MySqlServer';"& _
"Initial Catalog='Pubs';Integrated Security='SSPI';"Cnxn.OpenstrCnxn' Open a command object for a stored procedure ' with one parameter SetcmdByRoyalty=NewADODB.CommandSetcmdByRoyalty.ActiveConnection=CnxncmdByRoyalty.CommandText="byroyalty"cmdByRoyalty.CommandType=adCmdStoredProccmdByRoyalty.Parameters.Refresh' Get parameter value, execute the command ' and store the results in a recordset strRoyalty=InputBox("Enter royalty:")IfstrRoyalty=""ThenErr.Raise1,,"You either didn't enter royalty or canceled the input box. Exit the application"EndIfintRoyalty=Trim(strRoyalty)cmdByRoyalty.Parameters(1)=intRoyaltySetrstByRoyalty=cmdByRoyalty.Execute()' Open the Authors table to get author names for display SetrstAuthors=NewADODB.RecordsetstrSQLAuthors="Authors"rstAuthors.OpenstrSQLAuthors,Cnxn,adOpenForwardOnly,adLockPessimistic,adCmdTable' Print current data in the recordset ' and add author names Debug.Print"Authors with "&intRoyalty&" percent royalty"DoUntilrstByRoyalty.EOFstrAuthorID=rstByRoyalty!au_idDebug.Print" "&rstByRoyalty!au_id&", ";
rstAuthors.Filter="au_id = '"&strAuthorID&"'"Debug.PrintrstAuthors!au_fname&" "; rstAuthors!au_lnamerstByRoyalty.MoveNextLoop' clean up rstByRoyalty.CloserstAuthors.CloseCnxn.CloseSetrstByRoyalty=NothingSetrstAuthors=NothingSetCnxn=NothingExitSubErrorHandler:' clean up IfNotrstByRoyaltyIsNothingThenIfrstByRoyalty.State=adStateOpenThenrstByRoyalty.CloseEndIfSetrstByRoyalty=NothingIfNotrstAuthorsIsNothingThenIfrstAuthors.State=adStateOpenThenrstAuthors.CloseEndIfSetrstAuthors=NothingIfNotCnxnIsNothingThenIfCnxn.State=adStateOpenThenCnxn.CloseEndIfSetCnxn=NothingIfErr<>0ThenMsgBoxErr.Source&"-->"&Err.Description,,"Error"EndIfEndSub'EndRefreshVB