473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Parametrized ADO Stored Procedure from C++

4
I’m trying to call a stored procedure on my SQL 2008 server with the below code. When I look at the query with the SQL profiler I get the following:

Expand|Select|Wrap|Line Numbers
  1. exec GetUserID @Email='test@email.com',@Password='@Email'
What I expect to get is:

Expand|Select|Wrap|Line Numbers
  1. exec GetUserID @Email='test@email.com',@Password='123456'
Can someone explain what is going on please?

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2.  
  3. #import "C:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF", "EndOfFile")
  4.  
  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7.     try
  8.     {
  9.         ::CoInitialize(NULL);
  10.  
  11.         ADODB::_ConnectionPtr ConnectionPtr = NULL;
  12.         ADODB::_CommandPtr CommandPtr = NULL;
  13.         ADODB::_ParameterPtr ParameterPtr = NULL;
  14.  
  15.         char ConnectionString[200] = "Provider=SQLNCLI10; Server=IL47WS030501; Database=Demo; Trusted_Connection=yes;";
  16.  
  17.         ConnectionPtr.CreateInstance(__uuidof(ADODB::Connection));
  18.  
  19.         if(ConnectionPtr)
  20.         {
  21.             ConnectionPtr->Open(ConnectionString, "", "", 0);
  22.         }
  23.  
  24.         CommandPtr.CreateInstance(__uuidof(ADODB::Command));
  25.  
  26.         if(ConnectionPtr && CommandPtr)
  27.         {
  28.             CommandPtr->ActiveConnection = ConnectionPtr;
  29.             CommandPtr->CommandType = ADODB::adCmdStoredProc;
  30.             CommandPtr->CommandText = _bstr_t("GetUserID");
  31.             CommandPtr->NamedParameters = true;
  32.  
  33.             VARIANT vEmail;
  34.             vEmail.vt = VT_BSTR;
  35.             vEmail.bstrVal = _bstr_t("test@email.com");
  36.  
  37.             VARIANT vPassword;
  38.             vPassword.vt = VT_BSTR;
  39.             vPassword.bstrVal = _bstr_t("123456");
  40.  
  41.             CommandPtr->Parameters->Append(CommandPtr->CreateParameter(_bstr_t("@Email"), ADODB::adVarChar, ADODB::adParamInput, sizeof(vEmail), vEmail));
  42.             CommandPtr->Parameters->Append(CommandPtr->CreateParameter(_bstr_t("@Password"), ADODB::adVarChar, ADODB::adParamInput, sizeof(vPassword), vPassword));
  43.  
  44.             ADODB::_RecordsetPtr RecordsetPtr = CommandPtr->Execute(NULL, NULL, ADODB::adCmdStoredProc);
  45.         }
  46.  
  47.         return 0;
  48.     }
  49.     catch(...)
  50.     {
  51.     }
  52. }
Jan 8 '10 #1
1 3350
Ajaxx
4
I don’t know the details of why but I was able to get it working using the following code without a VARIANT instead:
Expand|Select|Wrap|Line Numbers
  1. CommandPtr->Parameters->Append(CommandPtr->CreateParameter(_bstr_t("@Email"), ADODB::adVarChar, ADODB::adParamInput, 50, "test@email.com"));
  2. CommandPtr->Parameters->Append(CommandPtr->CreateParameter(_bstr_t("@Password"), ADODB::adVarChar, ADODB::adParamInput, 50, "123456"));
Jan 10 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
22
by: nobody | last post by:
hello everybody, is there a way of creating an array with help of a function that would accept the name of this array as a parameter and then create global Array type variable of that name? so...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
1
by: Ajaxx | last post by:
I posted this in the C++ section but didn’t get any responses so I thought it might be more appropriate here. I’m trying to call a stored procedure on my SQL 2008 server with the below code. When...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.