I’m working on a VB6 project and my teacher wants me to use stored procedures or parameterized SQL statements instead of regular queries. The focus should be on the SQL side rather than VB code. I’m familiar with basic database connections like ADO and RDO but I can’t figure out how to implement this approach properly. What’s the best way to call SQL stored procedures from VB6? I need some guidance on setting this up correctly. Thanks for any help you can provide.
Working with stored procedures in VB6 is different - you’ll use the Command object instead of running SQL strings directly. Set up an ADODB.Command object, point its ActiveConnection to your database, and set CommandType to adCmdStoredProc. For CommandText, just use the procedure name (no EXEC or parentheses). Handle parameters through the Parameters collection - either use Parameters.Append to define them manually or call Parameters.Refresh to pull them from the database automatically. Use the Execute method for procedures that don’t return data, or set a Recordset equal to Execute for ones that do. This handles parameter binding automatically and stops SQL injection attacks, which is probably what your teacher’s worried about with regular query strings.
interesting approach from your teacher! are you writing the stored procs yourself or do they already exist in your database? what database are you using - SQL Server, Access, MySQL? setup varies depending on which one. have you tried Owen’s refresh method instead of manually defining params?
if you want to go for parameterized queries, ADODB.Command with CommandType set to adCmdText is the way! u can create params using cmd.Parameters.Append, it’s like cmd.CreateParameter(“@param1”, adVarChar, adParamInput, 50, “value”). much easier than dealing with stored procs. ur teacher would def approve!