Clarify VB .0 - SQL 2000 Connection - TechRepublic
Question
August 31, 2008 at 01:15 AM
itzmarvzki

Clarify VB .0 – SQL 2000 Connection

by itzmarvzki . Updated 17 years, 11 months ago

Hi! I’ve been studying how to connect vb 6.0 to sql 2000 since last week. I’ve start from scratch since this wasn’t taught at our school.

I’m a bit confused after analyzing the connections that I got from google. Its like people have different ways of connecting those 2 languages and for a newbie like me I don’t know what to follow.

I tried the code below that I got somewhere. I was able to connect with SQL and made a stored procedure. After the connection has opened, the application encountered an error at the execution of the ADODB command:

objCon.ConnectionString = ?MY CONNECTION?

objCon.Open objCon.ConnectionString
MsgBox “Connection opened”

With objCom
.CommandText = “GetRecords” ‘Name of the stored procedure
.CommandType = adCmdStoredProc ‘Type : stored procedure
.ActiveConnection = objCon.ConnectionString
End With

‘Create 2 output parameters
Set objPara = objCom.CreateParameter(“rows”, adInteger, adParamOutput)
Set objpara2 = objCom.CreateParameter(“CusID”, adVarChar, adParamOutput, 50)

‘Append the output parameters to command object
objCom.Parameters.Append objPara
objCom.Parameters.Append objpara2

‘Store the result in a recordset
Set objRS = objCom.Execute <<--- error here 'Open the recordset Do While Not objRS.EOF For k = 0 To objRS.Fields.Count - 1 Debug.Print objRS(k).Name & ": " & objRS(k).Value Next Debug.Print "_____" objRS.MoveNext Loop 'Close the recordset objRS.Close 'retrieve the output parameters values MsgBox "Total records returned: " & objPara.Value MsgBox objpara2.Value 'close connection objCon.Close ERROR: PROCEDURE HAS NO PARAMETERS AND ARGUMENTS ARE SUPPLIED. Could somebody kindly explain what I missed in the code, and please explain what the "do while loop" does (is it the code to display the data retrieved? if it is then what is this code for: "For k = 0 To objRS.Fields.Count - 1" and why is there a debug.print) Thanks in advance!

This discussion is locked

All Comments