send and return value from storedprocedure

Hi
i have to run a storedprocedure :

CREATE  PROCEDURE cins_ev
@out as int OUTPUT,
@in as int
AS
SELECT @out=@in+5
RETURN 10

that gets imput parameters and returns output parameters. I read the help 
apge about CRecordset and i wrote some code  .... but it doesnt work.
this is my code, can you explain me what have i to do to let it run???
thanks
Carlo

class my_event : public CRecordset
{
public:
 my_event(CDatabase* pDatabase = NULL);
 DECLARE_DYNAMIC(my_event)

// Field/Param Data
 //{{AFX_FIELD(my_event, CRecordset)
 long m_in;
 long m_out;
 //}}AFX_FIELD


// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(my_event)
 public:
 virtual CString GetDefaultConnect();    // Default connection string
 virtual CString GetDefaultSQL();    // Default SQL for Recordset
 virtual void DoFieldExchange(CFieldExchange* pFX);  // RFX support
 //}}AFX_VIRTUAL

// Implementation
#ifdef _DEBUG
 virtual void AssertValid() const;
 virtual void Dump(CDumpContext& dc) const;
#endif
};
/////////////////////////////////////////////////////////////////////////////
// my_event

IMPLEMENT_DYNAMIC(my_event, CRecordset)

my_event::my_event(CDatabase* pdb)
 : CRecordset(pdb)
{
 //{{AFX_FIELD_INIT(my_event)
 m_in = 2;
 m_out = 0;
 m_nFields = 3;
 //}}AFX_FIELD_INIT
 m_nDefaultType = snapshot;
}


CString my_event::GetDefaultConnect()
{
 return _T("ODBC;DSN=MS_SQL_db;UID=sa;PWD=pwd;");
}

CString my_event::GetDefaultSQL()
{
 return _T("{? = CALL dbo.cins_ev(?)}");
}

void my_event::DoFieldExchange(CFieldExchange* pFX)
{
 //{{AFX_FIELD_MAP(my_event)
   // output parameter
   pFX->SetFieldType( CFieldExchange::inputParam );
   RFX_Long( pFX, "@in", m_in );

   // input parameter
   pFX->SetFieldType( CFieldExchange:: outputParam);
   RFX_Long( pFX, "@out", m_out );
 //}}AFX_FIELD_MAP
}

/////////////////////////////////////////////////////////////////////////////
// my_event diagnostics

#ifdef _DEBUG
void my_event::AssertValid() const
{
 CRecordset::AssertValid();
}

void my_event::Dump(CDumpContext& dc) const
{
 CRecordset::Dump(dc);
}
#endif //_DEBUG


0
carletto.m (12)
3/9/2006 10:29:09 AM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
1218 Views

Similar Articles

[PageSpeed] 47

> .... but it doesnt work.

What does "it doesnt work" mean?

It fails to compile - what are error messages?
It fails to link - what are error messages?
It runs and abruptly terminates?
It runs and there is a run-time error message. If so, what?
It runs but no data is output?

I don't ever use words like "it doesnt work" as they don't inform anyone as
to what happened.

Also what database are you using?
If it is Access, Access does not support output parameters for SP's. SQL
Server does.

Stephen Howe


0
Stephen
3/9/2006 8:24:16 PM
Hi
i wrote a stored Procedure on my MSSQL server:

CREATE   PROCEDURE cins_ev
@in as int,
@out as int OUTPUT
AS
SELECT @out=@in+5

and i tried to call it using CRecordset in VC.
If i debug the code i can see that the call statment is executed and the 
values
gets and returned correctly, but it crashs. this is the output on the debug 
window

Detected memory leaks!
Dumping objects ->
dbcore.cpp(2666) : {83} normal block at 0x00335198, 2 bytes long.
 Data: <  > CD CD
plex.cpp(31) : {82} normal block at 0x003350E0, 124 bytes long.
 Data: <         K3     > 00 00 00 00 00 00 00 00 90 4B 33 00 01 00 00 00
map_pp.cpp(72) : {81} normal block at 0x00335058, 68 bytes long.
 Data: <         P3     > 00 00 00 00 00 00 00 00 F0 50 33 00 00 00 00 00
strcore.cpp(118) : {80} normal block at 0x00334FF0, 36 bytes long.
 Data: <            {CAL> 01 00 00 00 17 00 00 00 17 00 00 00 7B 43 41 4C
dbcore.cpp(3672) : {79} normal block at 0x00334D88, 8 bytes long.
 Data: <        > 04 00 00 00 04 00 00 00
dbcore.cpp(3666) : {78} normal block at 0x00334D40, 2 bytes long.
 Data: <  > 00 00
dbcore.cpp(3656) : {77} normal block at 0x00334CF8, 3 bytes long.
 Data: <   > 00 00 00
dbcore.cpp(3650) : {76} normal block at 0x00334C80, 60 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
plex.cpp(31) : {75} normal block at 0x00334F38, 124 bytes long.
 Data: <             J3 > 00 00 00 00 00 00 00 00 00 00 00 00 80 4A 33 00
strcore.cpp(118) : {74} normal block at 0x00334E90, 96 bytes long.
 Data: <    S   S   ODBC> 01 00 00 00 53 00 00 00 53 00 00 00 4F 44 42 43
dbcore.cpp(2283) : {68} client block at 0x00334BD8, subtype 0, 100 bytes 
long.
a CDatabase object at $00334BD8, 100 bytes long
C:\Documents and 
Settings\carlo\Documenti\INGV\daily\c_code\appo\appo.cpp(35) : {67} client 
block at 0x00334A80, subtype 0, 280 bytes long.
a my_event object at $00334A80, 280 bytes long
Object dump complete.
The thread 0xF08 has exited with code 3 (0x3).
The program 'C:\Documents and 
Settings\carlo\Documenti\INGV\daily\c_code\appo\Debug\appo.exe' has exited 
with code 3 (0x3).

this appens when it executes the istruction error -->  ASSERT((int)m_nFields 
== m_nFieldsBound);

in the function:
// Bind fields (if not already bound), then retrieve 1st record
void CRecordset::InitRecord()
{
 // fields to bind
 if (m_nFields != 0)
 {
  m_nFieldsBound = BindFieldsToColumns();
  // m_nFields doesn't reflect number of
  // RFX_ output column calls in Do[Bulk]FieldExchange

m_nFields=2, m_nFieldsBound=0

error -->  ASSERT((int)m_nFields == m_nFieldsBound);

  // Allocate the data cache if necessary
  if (m_nFields > 0 && m_bCheckCacheForDirtyFields)
   AllocDataCache();
 }
 else
  // No fields to bind, don't attempt to bind again
  m_nFieldsBound = -1;
}

i dont understand what is appening
can you help me???
Thanks a lot

Carlo












this is the code:

/////////////////////////////////////////////////////////////////////////////
// my_event recordset
#include "stdafx.h"

class my_event : public CRecordset
{
public:
 my_event(CDatabase* pDatabase = NULL);
 DECLARE_DYNAMIC(my_event)

// Field/Param Data
 //{{AFX_FIELD(my_event, CRecordset)
 long m_in;
 long m_out;
 //}}AFX_FIELD


// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(my_event)
 public:
 virtual CString GetDefaultConnect();    // Default connection string
 virtual CString GetDefaultSQL();    // Default SQL for Recordset
 virtual void DoFieldExchange(CFieldExchange* pFX);  // RFX support
 //}}AFX_VIRTUAL

// Implementation
#ifdef _DEBUG
 virtual void AssertValid() const;
 virtual void Dump(CDumpContext& dc) const;
#endif
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately 
before the previous line.

#endif // 
!defined(AFX_MY_EVENT_H__971B36AF_F6D2_47AA_BCFF_1DEF1640A75A__INCLUDED_)

// my_event.cpp : implementation file
//

#include "stdafx.h"
#include "appo.h"
#include "my_event.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// my_event

IMPLEMENT_DYNAMIC(my_event, CRecordset)

my_event::my_event(CDatabase* pdb)
 : CRecordset(pdb)
{
 //{{AFX_FIELD_INIT(my_event)
// m_in = _T("2");
 m_in = 2;
 m_out = 0;
 m_nFields = 3;
 //}}AFX_FIELD_INIT
 m_nParams = 2;
 m_nDefaultType = snapshot;
}


CString my_event::GetDefaultConnect()
{
 return _T("ODBC;DSN=MS_SQL_db;UID=sa;PWD=pwd;");
}

CString my_event::GetDefaultSQL()
{
 return _T("{CALL dbo.cins_ev(?,?)}");
}

void my_event::DoFieldExchange(CFieldExchange* pFX)
{
 //{{AFX_FIELD_MAP(my_event)
   //input parameter
   pFX->SetFieldType( CFieldExchange::inputParam );
   RFX_Long( pFX, "@in", m_in );

   // output parameter
   pFX->SetFieldType( CFieldExchange:: outputParam );
   RFX_Long( pFX, "@out", m_out );
 //}}AFX_FIELD_MAP
}

/////////////////////////////////////////////////////////////////////////////
// my_event diagnostics

#ifdef _DEBUG
void my_event::AssertValid() const
{
 CRecordset::AssertValid();
}

void my_event::Dump(CDumpContext& dc) const
{
 CRecordset::Dump(dc);
}
#endif //_DEBUG

//////////////////////////
// inside the main
  // TODO: code your application's behavior here.
  my_event* pt_ev;
  pt_ev= new my_event;
  try{
   pt_ev->Open();
   cout<<pt_ev->m_in<<endl;
//   cout<<pt_ev->m_out<<endl;
   pt_ev->Close();
   delete pt_ev;

  }
  catch(CDBException* e){
   printf("Errore numero:%d\n",e->m_nRetCode);
   return(e->m_nRetCode);
  }





0
carletto.m (12)
3/13/2006 11:05:22 AM
> error -->  ASSERT((int)m_nFields == m_nFieldsBound);

I suspect you should set m_nFields to zero in
your constructor as your stored procedure
doesn't return any recordsets (i.e. zero columns), it only sets
an output parameter.

0
markc600 (4)
3/13/2006 11:20:10 AM
hi, tx a lot but it doesnt work...
if i set m_nFields to zero it crashs when it try to execute movenext in the
recordset
do you know why???
tx
Carlo

<markc600@hotmail.com> ha scritto nel messaggio 
news:1142248810.662114.248900@z34g2000cwc.googlegroups.com...
>> error -->  ASSERT((int)m_nFields == m_nFieldsBound);
>
> I suspect you should set m_nFields to zero in
> your constructor as your stored procedure
> doesn't return any recordsets (i.e. zero columns), it only sets
> an output parameter.
> 


0
carletto.m (12)
3/13/2006 11:53:27 AM
Presumably because you don't have a recordset to
execute the 'movenext' against.

0
markc600 (4)
3/13/2006 12:01:45 PM
i didnt write a movenext() in my code, it executes it in open()

BOOL CRecordset::Open(UINT nOpenType, LPCTSTR lpszSQL, DWORD dwOptions)
{
.....
  // Give derived classes a call before binding
  PreBindFields();

  // Fetch the first row of data
  MoveNext();

and this couse the error
any idea???
is there a way to tell it that it hasnt fetch the first record because it 
doesnt exist????
thanks again
carlo



<markc600@hotmail.com> ha scritto nel messaggio 
news:1142251305.212229.258250@e56g2000cwe.googlegroups.com...
>
> Presumably because you don't have a recordset to
> execute the 'movenext' against.
> 


0
carletto.m (12)
3/13/2006 12:12:44 PM
Suggest you check out Microsoft Knowledge Base
article Q181837

0
markc600 (4)
3/13/2006 12:53:42 PM
Reply:

Similar Artilces:

How do I send copies emails without sending attachments?
I send emails with attachments to our bank. My boss wants a copy of the email but not a copy of the attachment. How do I do that? Steve Bramblett wrote: > I send emails with attachments to our bank. My boss wants a copy of the > email but not a copy of the attachment. How do I do that? Each recipient gets the SAME copy of the e-mail. If you want different recipients to get different versions of your e-mail, you have to send different e-mails. ...

no data to return blank
I currently have this formula =IF(C8>0,C8-$G$3,"") in a series of cells which is fine when there is information but I get a # value error when there is nothing in the cells it looks to. Is there a way to have it leave the cell blank if there is no data in the cells it looks to? -- A. when i test this formula using blank cells for c8 & g3 i get a blank cell as a result. how is your sheet arranged? "Andmor" wrote: > I currently have this formula =IF(C8>0,C8-$G$3,"") in a series of cells which > is fine when there is information ...

No message in outbox
I tried to send a message with 1Mb attachment to 40 recipients in the bcc field. It gave me an error message from the isp's server, the message was NOT sent (I've checked), it did NOT arrive in Sent Items, but neither is it in the Outbox any more. I can send and receive email successfully. Problem is, every few minutes Outlook tells me it's sending message 1 of 1, it fails and gives me the same error message. Yet there is no message in the Outbox. But what happened to the original message when it first failed to send? I guess it's 'stuck' somewhere but I can...

Sending mail from selected email address
Hi All, As I have 4 email accounts set up in Outlook, I understand that I can send mail from each or any account. The accounts are listed under tools / Send and Receive / then each of the accounts. How can I choose which account to send from so that the recipient see's who I want it to be from?? Hope that explains it. Regards Alan On Sat, 16 Apr 2005 21:10:48 -1000, The Fatman <albaxter@optushome.com.au> wrote: > Hi All, > > As I have 4 email accounts set up in Outlook, I understand that I can > send > mail from each or any account. > > The acco...

Sending a macro to another PC-how?
How do you send a macro you've written to another PC so that they can save it in their Personal.xls file (at Program Files\Microsoft Office\Office\XLStart)? You can export a macro and save it, to do this from your workbook, right-click the workbook's icon and pick View Code. This icon is to the left of the "File" menu this will open the VBA editor, click on the module you want to save and go to file and export file, then save it to a floppy or what ever you backup to, then import it to the new workbook. -- Paul B Always backup your data before trying something new Using ...

Sending mail from remote location
my mail works great while at home. when I go on the road I can receive ail but not send. I get the following error message: Subject 'SKIDOO MACH Z 800LT (long track / long tunnel) (Jackson)', Account: 'Jeff', Server: 'smtp.charter.net', Protocol: SMTP, Server Response: '571 imp11 smtp.charter.net OTcuMTQ3LjE2LjIzMA== You must connect from Charter IP space. E1110', Port: 25, Secure(SSL): No, Server Error: 571, Error Number: 0x800CCC61 It worked on my last laptop and I have not been able to figure it out on this one. I can't remember what I...

Send and Recieve Fix
For a long time I had a problem with my Send/Recieve function in Outlook. This happended in both Outlook 2000 and my current version - 2007. I found I had to re-boot my computer to perform a Send/Recieve in Outlook. Otherwise the sequence would start then stop and say it could not perform due to an error. After extensive Internet and News Group research I decided it was time to run a check on disk errors. This Windows XP facility seemed to have fixed my Outlook problem. I did this about a few months ago now and I have since had no problems with my send and recieve. Unfortunately I do have ...

Unable to send?
Hi, I've got MOOL, and i"m usign ti with outlook. The emails that I'm sending are just "stuck" in the outbox? Can anyone give me an idea of what's going on? Rex Did it ever work? Are you able to receive? -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP Roland Schorr & Tower http://www.rolandschorr.com Microsoft OneNote FAQ: http://www.factplace.com/onenotefaq.htm **I apologize but I am unable to respond to direct requests for assistance. Please post questions and replies here in the newsgroup. Mahalo! "Rekks" <rex_flynn@hotmail.com> wrote ...

Sending messages in Outlook
We have a user that everytime that she sends an email she will get booted out of Outlook. The email does go through, but she will have to get out of Outlook. When she goes back into Outlook, everything is fine until she sends another message. Any help would be appreciated. ...

No Permission to Send/Receive Email???
I just replaced our server hardware, upgraded to WS 2k3 Enterprise and created a new domain. I transferred the client files and desktop on our desk/laptop computers over to the new domain. We do NOT have Exchange installed yet, but use Outlook 2002 with the email etc. saved on the client. One one client machine (mine), the email, calendar, etc are there, but when I hit the Send/Receive button, I get a message saying that I don't have permission to perform this operation. Also when I try and change the automatic check for email option it tells me I don't have permission. ...

Send Do Not Send
When I attempt to email via a print server - OutLook Express displays the message "A program is attempting to email on your behalf" Send or Do Not Send - How do you prevent this from happening? And just automatically send? ...

Sending on behalf... Exchange 2003
Hi everyone, Is there a better way to give a few users the ability to send mails also from the info@domain.com mailbox without having them logout and login to a different Outlook 2003 profile... Or without the text sending on behalf of... So my question is, Is there an easy way that a user can select another e-mail address and send mails out...? Thanks a lot in advance!! Regards, BY On Thu, 05 Oct 2006 12:57:12 GMT, "BY" <nospam@mail.com> wrote: >Hi everyone, > >Is there a better way to give a few users the ability to send mails also >from the info@dom...

What was Outlook sending?
Hi, I downloaded my messages using the option "send and receive all". However, the "Show Progress" box indicates that I was also 'sending something'. But I had nothing to send! I look in the "Sent items' folder and nothing was sent at this time. What was Outlook 2003 doing? Santista The usual response here is, "You have a virus". It could be that a virus program is using your Outlook to send spam and/or a copy of itself to people in your address book. I hope this is not the case, but please have the foresight (aftersight?) to look into ...

Outlook Can't Send Messages
This morning I fired up Outlook 2007 (running under Windows 7). It retrieved all new emails. I then tried to post a new email, (not a reply). However, the nano-second that I clicked on "Send" I received a reply from "System Administrator". It said this: Your message did not reach some or all of the intended recipients. Subject: The Train Meltdown Sent: 27-Jul-10 1:18 PM The following recipient(s) cannot be reached: xxxxx@xxxxx.com.au on 27-Jul-10 1:18 PM None of your e-mail accounts could send to this recipient. I have 3 active email ac...

'SEND' just sends it to the OUTBOX
Outlook 2007 on WinXP Home SP3. When I click 'SEND' when replying to an email it does not SEND but puts it in the OUTBOX. I have to click SEND/RECEIVE from the main page to actually SEND the email. Is there a setting I am missing? Thank you. "Peter" <lysdexic@hotmail.com> wrote in message news:eoOd1BM$KHA.5536@TK2MSFTNGP02.phx.gbl... > Outlook 2007 on WinXP Home SP3. When I click 'SEND' when replying to an > email it does not SEND but puts it in the OUTBOX. I have to click > SEND/RECEIVE from the main page to actually SEND the emai...

Rules Wizard and Send/Receive error
A couple of days ago, I received an alert from Norton Antivirus software that the file "belt.cab" was corrupted but could not be deleted. Fearing the worst, I manually deleted the file. Since then, Outlook appears to be completely disabled, with the symptoms being that several commands have disappeared from the Tools menu including Send/Receive (both), Rules Wizard, Out of Office Assistant. I can compose an email, but it will not send. I have checked my email accounts and all appears to be in order. Even after a complete reinstall, I cannot send/receive email. The on...

sending Access files
Is there a quick and easy way to send access files without Outlook blocking them. I exchange files with a limited selection of people so am happy that what I am sending and receiving is OK. I know that I can use WizZip but the knowledge database also suggests changing the .mdb extension. I don't know how to do this. Do I just right click over the file and choose open with Word? Or maybe there is a simpler way. Thanks When you send a file type that on Microsoft's potentially dangerous list, you get a message informing you that the recipient may not be able to access the file on...

Reading multiple values from another table.
I have a table with general information in it such as Subject, Reference Rumber, Comments. I would like to have another table with Company Reference and Responsibility. So when I create a new record including Subject and Reference Number, I could look up values from the second table to fill in multiple instances of Company Reference and Responsibility. A better example would be a form to order pizza. The main form would contain name, address, Size and type of pizza. Then from the same form, you would look up toppings from a seperate table to add multiple toppings to each instance of a pizza. ...

Trying to send emails from an external program
I am trying to send email from my accpac software and it makes me allow the email everytime. Is there a way I make my Outlook 2007 accept Accpac as a reliable source for sending emails?? tammy0005 wrote: > I am trying to send email from my accpac software and it makes me allow the > email everytime. Is there a way I make my Outlook 2007 accept Accpac as a > reliable source for sending emails?? MapiLab's security add-on (free) ...

Multiple Send to
Dear Experts, In any Document Library you have a Send To drop down option. This can only be configured once that is only one entry. I have to have 7 Custom Send To options. Does anyone know how to create more than 1 Sent To? Best Regards, -- Girish J Bhatia MOSS Certified, SharePoint Certified, MCSE2003, MCDBA, CCNA, CCNP, CCSA ...

Automatically sending with outlook 2002
I am running Outlook 2002. When I click send, to send an email, it goes into Outbox. I then need to click send/receive from Inbox. Is there anyway the email can just send automatically from the outbox to avoid having to click send in 2 steps? Thanks. Check Tools | Options | Mail Setup Is the option to send messages immediately selected? Also, check the Send/Receive Settings | Define Send/Receive Groups. -- PATRICK REED [Outlook - MVP]~~~~~~ -Microsoft Certified Professional (MCP) -Have you checked http://www.slipstick.com? -Please post your Outlook version! "Ronk"...

still problems with Exchange 2010 and sending to certain domains
We have done the following: made sure the PTR records matches the IP address of the send connector created an SPF record we are still having issues sending to certain domains and we are at a loss. I've done plenty of 2007 systems and never had this issue. What are we doing wrong? It simply doesn't make sense. Do you get an error message back from the receiving server? JE. On 1/26/2010 10:14 AM, Gene Whitley wrote: > We have done the following: > > made sure the PTR records matches the IP address of the send connector > > created an...

Problem Sending Email using Outlook 2000
I am attempting to send an email to a 130 person distribution list. The email is very short but has a 451 kb attachment. I am repeatedly getting the following message from System Administrator Your message did not reach some or all of the intended recipients. Subject: My Subject Sent: 5/28/2005 11:03 AM The following recipient(s) could not be reached: RecipientOne (E-mail) on 5/28/2005 11:03 AM No transport provider was available for delivery to this recipient. RecipientTwo (E-mail) on 5/28/2005 11:03 AM No transport provider was available ...

PLEASE HELP: Send email from Access with data in email body
Hi All, How can I send email from access with data displayed in the email body? I have a button "Email users" in access custom form that sends email to all the users, But I dont know how to send them their particular schedule only. For eg: Here is what My Table looks like: Users Day Time User1 M 13:00 User2 M 14:00 User3 T 15:00 User1 T 16:00 User3 W 17:00 User4 W 18:00 User4 Th 13:00 So basically, When I click "Email Users" Button, I want all the users to receive their respective schedules onl...

Opportunity Retrieve method not returning Id
I am trying to add functionality to the CRM such that CRM has the ability to duplicate or copy existing opportunities in order to create a new opportunity. What I want to do is to create a "Copy Opportunity" button on the Opportunity form.The button allows to navigate to a custom aspx page. By enabling parameter passing, I can pass the object type (opportunity)and object id to the custom aspx page. The code behind for this custom aspx page should create the new opportunity using the CRMOpportunity Create method, and maybe just have a text box where the user could type the name of th...