Okay, so I've decided that I'll go ahead and post some of my more interesting problems that I've encountered at work to my blog. It seems I have a habit of getting errors that only happen to me. Any code samples have been altered to hide the true intent of the program, but the concepts should be the same. I hope this helps someone out there.
I'm pretty green at Delphi. I have a program that must call a MS SQL stored procedure before executing the rest of its logic. Here's the code I've written (changes have been made here and there to protect confidentiality):
theProcedure := TStoredProc.Create( NIL ) ; theProcedure.DatabaseName := theTDatabase.DatabaseName ;
theProcedure.SessionName := theTDatabase.SessionName ;
theProcedure.StoredProcName := 'dbo.my_stored_proc' ;
theProcedure.Prepare;
theProcedure.ExecProc;
I get an error back that says: No parameter type for parameter ‘@Foo’
So I tried this
theProcedure := TStoredProc.Create( NIL ) ;
theProcedure.DatabaseName := theTDatabase.DatabaseName ;
theProcedure.SessionName := theTDatabase.SessionName ;
theProcedure.StoredProcName := 'dbo.my_stored_proc' ; theProcedure.ParamByName('@Foo').AsString := 'bar' ;
theProcedure.Prepare;
theProcedure.ExecProc;
I then get an error that says "Parameter ‘@Foo’ not found"
I tried leaving off the @. Same error as above (sans the @ sign).
Google doesn't seem to help either (only 6 results). It's as frustrating as frustration can get.
So I learned later on that I have to create the parameters before I can use them! Here's what the code should look like:
theProcedure := TStoredProc.Create( NIL ) ;
theProcedure.DatabaseName := theTDatabase.DatabaseName ;
theProcedure.SessionName := theTDatabase.SessionName ;
theProcedure.StoredProcName := 'dbo.my_stored_proc' ;
theTStoredProc.Params.CreateParam(ftInteger, '@Foo', ptInput) ;
theProcedure.ParamByName('@Foo').AsString := 'bar' ;
theProcedure.Prepare;
theProcedure.ExecProc;
Gee I wonder why none of the sites listed on Google bothered to mention that.