Stored procedure call with ADO

Closed Thread

Join Date: Mar 2005
Posts: 1
Reputation: pjnutt is an unknown quantity at this point 
Solved Threads: 0
pjnutt pjnutt is offline Offline
Newbie Poster

Stored procedure call with ADO

 
0
  #1
Mar 11th, 2005
Hello,

I am attempting to make a stored procedure call to an ADO. I will paste in the try loop. Problem is code compiles and runs, however; the stored procedure never runs. It's supposed to create a row in the DB, and the row is never created. If I run the proc in a SQL query session, it runs succesfully, so I know that the proc is good. If anyone could be of any help, I would appreciate it. I am using sample code that I found at another site, my first thought was that I may have to use another function, not execute(), I'm at a loss.......

  1. try
  2. {
  3. HRESULT result;
  4.  
  5. //Connect to database
  6. result = ::CoInitialize(NULL);
  7. if (FAILED(result)) throw HookException("COM initialize failed.");
  8.  
  9. result = connection.CreateInstance(__uuidof(Connection));
  10. if (FAILED(result)) throw HookException("Could not create connection instance.");
  11.  
  12. result = connection->Open("DSN=WFC_DSN;UID=suprkron;PWD=skron96", "", "", adConnectUnspecified);
  13. if (FAILED(result)) throw HookException("Could not connect to database.");
  14.  
  15. result = preparedCommand.CreateInstance(__uuidof(Command));
  16. if (FAILED(result)) throw HookException("Could not create prepared command.");
  17.  
  18. preparedCommand->CommandText = "NGP_VALLABORACCT";
  19. preparedCommand->ActiveConnection = connection;
  20. preparedCommand->CommandType = adCmdStoredProc;
  21.  
  22. //LL 1
  23. vLl1.vt = VT_I2;
  24. vLl1.iVal = ll1;
  25. inputParam = preparedCommand->CreateParameter(_bstr_t("1"),
  26. adInteger,
  27. adParamInput,
  28. sizeof(int),
  29. vLl1);
  30. preparedCommand->Parameters->Append(inputParam);
  31. //LL 2
  32. vLl2.vt = VT_I2;
  33. vLl2.iVal = ll2;
  34. inputParam = preparedCommand->CreateParameter(_bstr_t("2"),
  35. adInteger,
  36. adParamInput,
  37. sizeof(int),
  38. vLl2);
  39. preparedCommand->Parameters->Append(inputParam);
  40. //LL 3
  41. vLl3.vt = VT_I2;
  42. vLl3.iVal = ll3;
  43. inputParam = preparedCommand->CreateParameter(_bstr_t("3"),
  44. adInteger,
  45. adParamInput,
  46. sizeof(int),
  47. vLl3);
  48. preparedCommand->Parameters->Append(inputParam);
  49. //LL 4
  50. vLl4.vt = VT_I2;
  51. vLl4.iVal = ll4;
  52. inputParam = preparedCommand->CreateParameter(_bstr_t("4"),
  53. adInteger,
  54. adParamInput,
  55. sizeof(int),
  56. vLl4);
  57. preparedCommand->Parameters->Append(inputParam);
  58. //LL 5
  59. vLl5.vt = VT_I2;
  60. vLl5.iVal = ll5;
  61. inputParam = preparedCommand->CreateParameter(_bstr_t("5"),
  62. adInteger,
  63. adParamInput,
  64. sizeof(int),
  65. vLl5);
  66. preparedCommand->Parameters->Append(inputParam);
  67. //LL 6
  68. vLl6.vt = VT_I2;
  69. vLl6.iVal = ll6;
  70. inputParam = preparedCommand->CreateParameter(_bstr_t("6"),
  71. adInteger,
  72. adParamInput,
  73. sizeof(int),
  74. vLl6);
  75. preparedCommand->Parameters->Append(inputParam);
  76. //LL 7
  77. vLl7.vt = VT_I2;
  78. vLl7.iVal = ll7;
  79. inputParam = preparedCommand->CreateParameter(_bstr_t("7"),
  80. adInteger,
  81. adParamInput,
  82. sizeof(int),
  83. vLl7);
  84. preparedCommand->Parameters->Append(inputParam);
  85.  
  86. returnVal.vt = VT_I2;
  87. returnVal.iVal = 0;
  88. returnParam = preparedCommand->CreateParameter(_bstr_t("return"),
  89. adNumeric,
  90. adParamReturnValue,
  91. sizeof(_variant_t),
  92. returnVal);
  93. preparedCommand->Parameters->Append(returnParam);
  94.  
  95. resultSet = preparedCommand->Execute(&rowsAffected, NULL, adCmdStoredProc);
  96. printf("Complete, rows effected: %d", rowsAffected.lVal);
  97. }

<< moderator edit: added [code][/code] tags >>
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC