Trying to figure out some basic applications of Stored Procedures with VB (VB6).
I have the following Stored Procedure in MS SQL Server:
MYSp is connected to my app through a DataEnvironment object as a data command named "MyCommand" which has (in addition to the RETURN_VALUE), two parameters: (1) "MyState" and (2) "MySort" (both of Data Type "adVarChar" and Host Data Type "String(VT_BSTR)");Code:CREATE PROCEDURE dbo.MySP @MyState varchar(15) = 'California', @MySort varchar (50) = 'Zip' As Declare @MySz varchar(100) Select @MySz = 'Select * From MyTable Where State = ' + @MyState + ' Order by ' + @MySort Exec(@MySz) GO
I have called MyProcedure from VB6 as follows:When I do, I get the following error:VB Code:
Private Sub Form_Load() Text1.Text = "" DE.MyCommand4 "CA", "Zip" With DE.rsMyCommand Do While Not .EOF If Not Text1.Text = "" Then Text1.Text = Text1.Text + ", " End If Text1.Text = Text1.Text + .Fields(1).Value .MoveNext Loop .Close End With End Sub
MyTable looks as follows:Run-time error '-2147217900 (80040e14)':
Invalid column name 'California'.
Why is VB seeking to equate the MyState variable with a column in the SQL DB when the SQL statement places the @MyState variable into a conditional context as inIDNo Name City State Zip
{39... Jose Coral Gables Florida 035180895
{08... Gretchen WLA California 900250012
{FA... Leon Jr. Miami Florida 035120088
{79... Leon Sr. LA California 900690354
{F5... Zack WLA California 900250012????Code:' . . . WHERE State = " + @MyState
I appreciate any help I can get. Thanks.


Reply With Quote