Pro * C/C ++ Windows Programming

Source: Internet
Author: User

Pro * C/C ++ Windows Programming

 

Source: Phoenix. Yuwen 2005-11-21

[1] Create a winproc. PC file first

Write the Oracle database-related operations into classes and functions.

Note during pre-Compilation:

You must modify the code, parse, cpp_suffix

1: Select CPP for code

2: Select none or partial for parse.

3: cpp_suffix CPP

[2] generate the winproc. cpp file after successful pre-Compilation

Change this file to the header file winproc. h and import it to your project.

Reference the classes and functions in winproc. h In the Project Development Program to perform database operations.

 

The following is a winproc. PC file I wrote.

# Include <iostream. h>

# Include <string. h>

# Include <stdlib. h>

# Include <stdio. h>

# Include <sqlca. h>

# Include <afxwin. h>

 

# Include <release a. h>

 

Exec Oracle option (release_cursor = yes );

 

Exec SQL include sqlca;

/* SQL variable Declaration */

Exec SQL begin declare section;

 

Exec SQL end declare section;

 

Class oracle_proc

{

Public:

Void connect_oracle ();

Void select_ SQL ();

Void SQL _error ();

};

Void oracle_proc: connect_oracle ()

{

/* Log on to the database using user: System/manager */

Exec SQL CONNECT: "Scott" identified by: "Scott ";

/* When Logon fails */

If (sqlca. sqlcode <0)

{

Afxmessagebox (sqlca. sqlerrm. sqlerrmc );

Exec SQL rollback work release;

}

/* When the connection is successful */

Else

{

Afxmessagebox ("/nconnected to Oracle! /N ");

}

 

};

Void oracle_proc: SQL _error ()

{

Afxmessagebox ("some error... ");

};

Void oracle_proc: select_ SQL ()

{

/* Assign an SQL statement value to an insert statement */

Exec SQL begin declare section;

Char temp [20];

Exec SQL end declare section;

/* Execute SQL */

Exec SQL select dname into: temp from Scott. Dept where deptno = '28 ';

Exec SQL commit work release;

/* Output SQL statement */

Afxmessagebox (temp );

};

Generate winproc. cpp after pre-Compilation

Create an MFC program and import the header file winproc. H to the project. Remember to add the library file orasql8.lib.

Make an experiment in it to see:

Void ctestprocdlg: onbutton1 ()

{

// Todo: add your control notification handler code here

Oracle_proc ora;

Ora. connect_oracle ();

Ora. select_ SQL ();

// Ora. SQL _error ();

}

The result shows that we directly access the Oracle database through MFC + Pro * C/C ++, and the whole process is very simple,

OO ^ ____ ^ oo

Discuss issues together

Email: yuwen05@126.com

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.