Help with using COM save data!

Results 1 to 6 of 6

Thread: Help with using COM save data!

  1. #1
    Charles Guest

    Default Help with using COM save data!

    Hello, I&#039;m getting the an error message(listed below) when using COM with astored procedure to save data to a database. Further below are the codes that I&#039;ve witten, can you please take a look and tell me how I can fix this problem. The error occurs at line: Set var2 = var1.InsertOrder(strAccountType)<BR><BR>Thanks<BR> <BR>Error Type:<BR>Microsoft VBScript runtime (0x800A01A8)<BR>Object required: &#039;[undefined]&#039;<BR>/StockNet/snOrderSubmittedMsgCOM.asp, line 49<BR><BR>ASP<BR>***<BR>&#060;%@ Language=VBScript %&#062;<BR>&#060;HTML&#062;<BR>&#060;HEAD&#062;<BR >&#060;META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"&#062;<BR>&#060;LINK REL=STYLESHEET TYPE="text/css" HREF="Styles/SNStyles.css"&#062;<BR>&#060;/HEAD&#062;<BR>&#060;BODY bgcolor="#fffff6"&#062;<BR>&#060;center&#062;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#060;i mg src="images/StockNetTitle.gif"&#062;&#060;/center&#062;<BR>&#060;!--#include file=""--&#062;<BR>&#060;!--#include file=""--&#062; <BR>&#060;%<BR> &#039;Declare variables<BR> Dim objConnection<BR> Dim objCommand<BR> Dim objParam<BR> Dim strAccountType<BR> &#039; Call a component and pass variables to its method<BR> Dim var1, var2<BR> Set var1 = CreateObject("SNCls3.InsertSNOrder")<BR> strAccountType = "Market"<BR> Set var2 = var1.InsertOrder(strAccountType) <BR>%&#062; <BR><BR>COM<BR>***<BR> Public Function InsertOrder(strAccountType)<BR> &#039; Open Connection<BR> Dim connection As New ADODB.connection<BR> Dim recordset As New ADODB.recordset<BR> Dim objCommand As New ADODB.Command<BR> Dim objParam As New ADODB.Parameter<BR> test = strAccountType<BR> With connection<BR> .ConnectionString = DB_CONNECTIONSTRING<BR> .Open<BR> End With<BR> <BR> &#039;Open Command Object<BR> Set objCommand = New ADODB.Command<BR> With objCommand<BR> .CommandText = "sp_EnterNewOrderCOM"<BR> .CommandType = adCmdStoredProc<BR> .ActiveConnection = connection<BR> End With<BR>Set objParam = objCommand.CreateParameter("@AccountType", adChar, adParamInput, 10, strAccountType)<BR>objCommand.Parameters.Append objParam<BR>Set objParam = objCommand.CreateParameter("@RecordID", adInteger, adParamOutput)<BR>objCommand.Parameters.Append objParam<BR>objCommand.Execute<BR>End Function<BR><BR>Stored Procedure<BR>****************<BR><BR>CREATE PROCEDURE sp_EnterNewOrderCOM<BR>@AccountType char(10),<BR>@RecordID int OUTPUT<BR> AS<BR><BR><BR>DECLARE @Return int,<BR> @TranCnt tinyint<BR><BR><BR> <BR>SELECT @TranCnt = @@TRANCOUNT<BR> <BR>IF @TranCnt = 0<BR>BEGIN TRAN -- Only begin tran when trancount is 0 to avoid rolling back to wrong tran at nested tran<BR><BR>SELECT @RecordID =ISNULL(MAX(RecordID)+1,1)<BR>FROM SNOrderEntry (UPDLOCK)<BR>SET IDENTITY_INSERT SNOrderEntry ON<BR>INSERT SNOrderEntry(<BR>RecordID,<BR>AccountType<BR>)<BR> VALUES(<BR>@RecordID,<BR>@AccountType<BR>)<BR><BR> SELECT @Return = @@ERROR<BR>IF @TranCnt = 0<BR> IF @Return = 0 COMMIT TRAN<BR> ELSE ROLLBACK TRAN<BR><BR>RETURN @Return<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR ><BR>

  2. #2
    <eop> Guest

    Default Set var2 = var1.InsertSNOrder(strAccountType)


  3. #3
    Charles Guest

    Default RE: Set var2 = var1.InsertSNOrder(strAccountType)

    The class name is InsertSNOrder and the method name is InsertOrder, your suggestion did not work, any other ideas?<BR><BR>Thanks for your reply.

  4. #4
    Sandy Breon Guest

    Default define explicit return from InsertOrder

    and set the return value from within InsertOrder in your COM method call.<BR><BR>For example:<BR><BR>Public Function InsertOrder(ByVal strAccountType as String) AS BOOLEAN<BR><BR>&#039;code goes here<BR> InsertOrder = True<BR>End Function<BR><BR><BR>Then in VB Script<BR><BR>var2 = var1.InsertOrder(strAccountType)<BR>If var2 = true Then<BR> &#039;do something<BR>Else<BR> &#039;do something<BR>End If<BR><BR><BR>

  5. #5
    Charles Guest

    Default RE: define explicit return from InsertOrder

    Hello,<BR><BR>I tried your suggestion and although I don&#039;t get an error message,the data does not save to the table. Can you give me some more help on how to fix this problem.

  6. #6
    Sandy Breon Guest

    Default Is your COM object transactional

    If your COM object is transactional, you may have to commit the transaction within the same objectcontext.<BR><BR>If your COM object is NOT transactional, I&#039;m not sure what would cause the data not to save????? Are you handling errors?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts