ODBC C编程访问数据库
新建一个Win32 Application,并在相应文件夹下新建一个book.mdb, 里面有一个表BookInfo,表中有以下几例:
id:
BookName:
Author:
等;
//------------------------------------------------------------------------------
// Copyright (c) 2009 eryar All rights reserved.
//
// File : Main.cpp
// Author : eryar@163.com
// Date : 2009-11-8 16:09
// Version : 1.0v
//
// Description : ODBC编写程序访问数据库的操作示例。
//
//==============================================================================
#include <windows.h>
#include <sqlext.h>
#include <odbcinst.h>
#define IDM_FILE_OPEN 100001
#define IDM_FILE_EXIT 100002
#define IDM_HELP_CONTENT 200001
#define IDM_HELP_ABOUT 200002
#define IDM_DATA_CONNECT 300001
#define IDM_DATA_QUERY 300002
char* szAppName = "ODBC Demo";
HINSTANCE ghInst;
HMENU WinMainMenu(HWND);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HWND hWnd;
MSG Msg;
WNDCLASS wndclass;
char* szClassName = "CODBC";
ghInst = hInstance;
wndclass.style = CS_HREDRAW|CS_VREDRAW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szClassName;
if (!RegisterClass(&wndclass)) {
MessageBox(NULL, "This program requires Windows NT! ", szAppName, MB_OK|MB_ICONERROR);
return 0;
}
hWnd = CreateWindow(szClassName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while (GetMessage(&Msg, NULL, 0, 0)) {
Tra
相关文档:
源码:
# include <stdio.h>
/* 子函数声明 */
int square(int x); // 实现求平方值的子函数
int cube(int y); // 实现求立方值的子函数
int main()
{
int m = 12;
int n = 4;
printf("%d %d\n", sq ......
C Sharp(C#)中如何删除文件(文件夹)
直接删除:
using System.IO;
...
string filePath = @"D:\...\xxx.xxx";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
else
{
Console. ......
兰大论坛上的一个帖子~~
学东西,往往实例才是最让人感兴趣的,老是学基础理论,不动手,感觉没有成就感,呵呵。
下面先来一个实例。我们通过创建两个线程来实现对一个数的递加。
或许这个实例没有实际运用的价值,但是稍微改动一下,我们就可以用到其他地方去拉。
下面是我们的代码:
/*thread_example.c : c ......
这篇文章介绍在LINUX下进行C语言编程所需要的基础知识.在这篇文章当中,我们将会学到以下内容:
源程序编译
Makefile的编写
程序库的链接
程序的调试
头文件和系统求助
--------------------------------------------------------------------------------
1.源程序的编译
在Linux下面,如果要编译一个C ......
#include <stdio.h>
#include <unistd.h>
#define FOO "foo"
int main(void)
{
if(!access(FOO, F_OK))
{
if(!unlink(FOO))
{
}
else
{
printf("remove %s failed\n", FOO);
}
}
else
{
printf("%s not existed\ ......