使用wxWidgets的ODBC链接ACCESS数据源
学习wxWidgets的时候想用它连接数据库,不过wxWidgets的学习资料非常少,和ODBC有关的就更少,网络上找到的都不知道为什么无法正确运行。这是在CSDN上朋友的帮助下搞定的,自己验证过可以正确编译和运行、成功读取数据内容的代码:
wxWidgets版本:2.8.10(2.9以后的版本不支持ODBC);
将wxWidgets\include\wx\msw\setup.h中的#define wxUSE_ODBC 设置为1,然后再进行编译;
工程配置(事实上,将一个Sample项目拖过来进行修改更方便):
项目属性-配置属性-链接器-输入-附加依赖项添加以下内容:
wxmsw28d_core.lib
wxbase28d.lib
wxbase28d_odbc.lib
wxtiffd.lib
wxjpegd.lib
wxpngd.lib
wxzlibd.lib
wxregexd.lib
wxexpatd.lib
winmm.lib
comctl32.lib
rpcrt4.lib
wsock32.lib
odbc32.lib
项目属性-配置属性-链接器-常规-附加库目录添加以下内容(注意正确对应自己工程和库的相对路径):
..\..\wxWidgets\lib\vc_lib
项目一共分了4个文件,两个类,代码如下:
theFrame.h
#ifndef THEFRAME_2009_12_26_H_
#define THEFRAME_2009_12_26_H_
#pragma once
#include "wx/wx.h"
#include <wx/db.h>
#include <wx/dbtable.h>
class theFrame : public wxFrame
{
public:
theFrame(const wxString &Title, const wxPoint& pos, const wxSize& size);
virtual ~theFrame();
void OnSize(wxSizeEvent &Event);
void OnButton(wxCommandEvent &Event);
wxDbConnectInf *ConnectConfig;
wxDb *theConnect;
wxStaticText *theTex;
wxDbTable *tbl;
int theID;
wxChar theName[10];
protected:
private:
DECLARE_EVENT_TABLE()
};
#endif
theFrame.cpp
#include "theFrame.h"
//告诉引擎将事件和处理函数联系起来
BEGIN_EVENT_TABLE(theFrame, wxFrame)
EVT_SIZE(theFrame::OnSize)
EVT_BUTTON(wxID_OK, theFrame::OnButton)
END_EVENT_TABLE()
theFrame::theFrame(const wxString& Title, const wxPoint& pos, const wxSize& size) :
wxFrame((wxFrame *)NULL, wxID_ANY, Title, pos, size)
{
theID = 0;
memset(theName, 0, sizeof(theName));
tbl
相关文档:
create table(access环境下)自动编号类型的写法
方法一:
create table tablename(id counter constraint primarykey primary key)
需要注意的地方是:第二个primary中间有空格,另外,关键字不区分大小写.
方法二:
create table mytb (id autoincrement(25,1) primary key,age int)
或
create table testtb (id aut ......
这两天开始学习ACCESS数据库的连接,感觉不是特别的顺手,对数据库的连接的整个过程还不是特别的了解。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
usi ......
BOOL GetAllFields(_RecordsetPtr m_pRecordset,CStringArray & fieldsarray)
{
if (m_pRecordset)
{
if (m_pRecordset->State)
&nbs ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
namespace TaobaoDAL
{
public class DBHelper
{
//引导数据库连接数据库调用Web.Config文件
private static OleDbConnection conn ......