Add ODBC to VC ++

Source: Internet
Author: User

1. Create an EXE file based on the dialog box

2. Add in stdafx. h

# Include <afxdb. h>
# Include <afxtempl. h>

3. Add:

# Include <odbcinst. h>
# Import "C: \ Program Files \ common files \ System \ ADO \ msado15.dll" RENAME ("EOF", "adoeof ")
Using namespace ADODB;
Typedef bool (winapi * sqlconfigdatasource_function) (hwnd, word, lpcstr, lpcstr );
4. Add:

Hinstance H =: loadlibrary ("odbccp32.dll ");
: Sqlconfigdatasource_function pconfigdatasource = 0;
Pconfigdatasource = (sqlconfigdatasource_function) getprocaddress (H, "sqlconfigdatasource ");
// Use the dynamic path to set the ODBC Data Source
Char sdirectory [256];
: Getcurrentdirectory (256, sdirectory );
Strcat (sdirectory, "\ student. mdb ");
Char ss [256] = "DSN = studb0dbq = ";
Strcat (SS, sdirectory );
Ss [9] = 0; // distinguish between front and back substrings
Int length = strlen (SS );
Ss [length] = 0; // because this parameter ends with a dual Terminator
Bool res = pconfigdatasource (null, odbc_add_dsn, "Microsoft Access Driver (*. mdb)", SS );
: Freelibrary (h); // release dynamic Connection Library Resources

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.