473,414 Members | 1,948 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,414 software developers and data experts.

Parametrized ADO Stored Procedure from C++

4
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 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'
It seems as if the first parameter is stepping on the second. As ‘@Email’ is a remnant of the first. Can someone explain what is going on?
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 9 '10 #1
1 8145
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...
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) ?
1
by: larry mckay | last post by:
Hi, I'd like to use a datagrid with a 1. most grid's use SQL data adapters as a datasource. I'd like to use a parametrized query into a stored procedure (specifically a sqldatareader)...
3
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
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
0
by: SOI_0152 | last post by:
Hi all! Happy New Year 2008. Il hope it will bring you love and happyness I'm new on this forum. I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c. Everything works...
1
by: Ajaxx | last post by:
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: exec GetUserID...
2
by: gyanendar | last post by:
How can i run parametrized input(2) stored procedure with 3 results fields on SQL prompt? Please help.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.