数据库编程遇到的一个怪问题??? 在classwizard中创建一个继承于CRecordSet类,并连接好了数据库,这个类跟书本的给出的例子一模一样,但却出现了错误,就是:'CRecordset' : base class undefined,请问怎么会这样,怎样才能解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在格stdafx.h包含了#include <afxdb.h>没有? .h文件:#if !defined(AFX_ADDCATEGDLG_H__2F818918_4AB0_461D_BEC6_EC71B561B32B__INCLUDED_)#define AFX_ADDCATEGDLG_H__2F818918_4AB0_461D_BEC6_EC71B561B32B__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// AddCategDlg.h : header file///////////////////////////////////////////////////////////////////////////////// CAddCategDlg dialogclass CAddCategDlg : public CDialog{// Constructionpublic: CAddCategDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data //{{AFX_DATA(CAddCategDlg) enum { IDD = IDD_ADD_CATEG_DLG }; CString m_strName; CString m_strNote; //}}AFX_DATA// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAddCategDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementationprotected: // Generated message map functions //{{AFX_MSG(CAddCategDlg) virtual void OnOK(); //}}AFX_MSG DECLARE_MESSAGE_MAP()private: int WriteData();};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_ADDCATEGDLG_H__2F818918_4AB0_461D_BEC6_EC71B561B32B__INCLUDED_).cpp文件:// AddCategDlg.cpp : implementation file//#include "stdafx.h"#include "MyMFCODBCSmpl.h"#include "AddCategDlg.h"#include "MainFrm.h"#include "CategorySet.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CAddCategDlg dialogCAddCategDlg::CAddCategDlg(CWnd* pParent /*=NULL*/) : CDialog(CAddCategDlg::IDD, pParent){ //{{AFX_DATA_INIT(CAddCategDlg) m_strName = _T(""); m_strNote = _T(""); //}}AFX_DATA_INIT}void CAddCategDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAddCategDlg) DDX_Text(pDX, IDC_CATEG_NAME, m_strName); DDX_Text(pDX, IDC_CATEG_NOTE, m_strNote); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAddCategDlg, CDialog) //{{AFX_MSG_MAP(CAddCategDlg) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CAddCategDlg message handlersvoid CAddCategDlg::OnOK() { // TODO: Add extra validation here CDialog::OnOK();}int CAddCategDlg::WriteData(){ int n Ret=-1; if(m_strName.IsEmpty()) { AfxMessageBox("产品分类名称不能为空!"); return nRet; } CDatabase db; if(!db.Open(_T("MyNWind"))) { AfxMessageBox("数据源连接失败!"); return nRet; } if(!db.BeginTrans()) return nRet; TRY { CString strSql="Insert into Categories(CategoryName,Description) values("; CString strTemp; strTemp=m_strName; strSql+="'"; strSql+=strTemp; strSql+="'"; strSql+=","; strSql+="'"; strTemp=m_strNote; strSql+="'"; strSql+=")"; db.ExecuteSQL(strSql); db.CommitTrans(); } CATCH(CDBException,e) { db.Rollback(); AfxMessageBox(e->m_strError); e->Delete(); return nRet; } END_CATCH; CCategorySet *pSet=new CCategorySet(&db); if(!pSet->IsOpen())pSet->Open(); pSet->m_strSort="ASC CategoryID"; pSet->MoveLast(); nRet=pSet->m_CategoryID; pSet->Close(); delete pSet; db.Close(); return nRet;} 把CategorySet.h和CategorySet.cpp贴出来 #if !defined(AFX_CATEGORYSET_H__CFCF419B_161E_45B8_BDBC_367EA1A87A85__INCLUDED_)#define AFX_CATEGORYSET_H__CFCF419B_161E_45B8_BDBC_367EA1A87A85__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// CategorySet.h : header file///////////////////////////////////////////////////////////////////////////////// CCategorySet recordsetclass CCategorySet : public CRecordset{public: CCategorySet(CDatabase* pDatabase = NULL); DECLARE_DYNAMIC(CCategorySet)// Field/Param Data //{{AFX_FIELD(CCategorySet, CRecordset) long m_CategoryID; CString m_CategoryName; CString m_Description; CLongBinary m_Picture; //}}AFX_FIELD// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CCategorySet) 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;.h文件#endif};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CATEGORYSET_H__CFCF419B_161E_45B8_BDBC_367EA1A87A85__INCLUDED_).cpp文件:// CategorySet.cpp : implementation file//#include "stdafx.h"#include "MyMFCODBCSmpl.h"#include "CategorySet.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CCategorySetIMPLEMENT_DYNAMIC(CCategorySet, CRecordset)CCategorySet::CCategorySet(CDatabase* pdb) : CRecordset(pdb){ //{{AFX_FIELD_INIT(CCategorySet) m_CategoryID = 0; m_CategoryName = _T(""); m_Description = _T(""); m_nFields = 4; //}}AFX_FIELD_INIT m_nDefaultType = snapshot;}CString CCategorySet::GetDefaultConnect(){ return _T("ODBC;DSN=MyNWind");}CString CCategorySet::GetDefaultSQL(){ return _T("[dbo].[Categories]");}void CCategorySet::DoFieldExchange(CFieldExchange* pFX){ //{{AFX_FIELD_MAP(CCategorySet) pFX->SetFieldType(CFieldExchange::outputColumn); RFX_Long(pFX, _T("[CategoryID]"), m_CategoryID); RFX_Text(pFX, _T("[CategoryName]"), m_CategoryName); RFX_Text(pFX, _T("[Description]"), m_Description); RFX_LongBinary(pFX, _T("[Picture]"), m_Picture); //}}AFX_FIELD_MAP}/////////////////////////////////////////////////////////////////////////////// CCategorySet diagnostics#ifdef _DEBUGvoid CCategorySet::AssertValid() const{ CRecordset::AssertValid();}void CCategorySet::Dump(CDumpContext& dc) const{ CRecordset::Dump(dc);}#endif //_DEBUG 错误,就是:'CRecordset' : base class undefined 用点心看一下,应该是CRecrodSet啊 class CCategorySet : public CRecordset CRecordset是没有错的,将程序发给我吧[email protected] 可以的话,也给一份代码给我好吗?[email protected] 这段我看不懂 谁帮我翻译下 每行都要哦 讲得越详细越好 一个文件提取的程序有问题请各位帮忙看看! 初学mfc wininet中可以支持javascript吗?应该怎样实现? 对象重叠显示问题 悬赏:向大家请教一个问题 什么类可以有“句柄”? 请教 n K字节大小的数据块取CRC32校检码的重码概率为多少及计算方式 如何把SendList(DATA &data,DWORD n)变成COM接口的方法呢? 关于CRegistry类,谢谢了 在VC++.NET中的一个简单问题?解决立即送分!!!!! 将A程序中参数传给B.EXE文件,B该如何得到的这些参数参数?有没有详细的代码
包含了#include <afxdb.h>没有?
#if !defined(AFX_ADDCATEGDLG_H__2F818918_4AB0_461D_BEC6_EC71B561B32B__INCLUDED_)
#define AFX_ADDCATEGDLG_H__2F818918_4AB0_461D_BEC6_EC71B561B32B__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// AddCategDlg.h : header file
///////////////////////////////////////////////////////////////////////////////
// CAddCategDlg dialogclass CAddCategDlg : public CDialog
{
// Construction
public:
CAddCategDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CAddCategDlg)
enum { IDD = IDD_ADD_CATEG_DLG };
CString m_strName;
CString m_strNote;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAddCategDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CAddCategDlg)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()private:
int WriteData();
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_ADDCATEGDLG_H__2F818918_4AB0_461D_BEC6_EC71B561B32B__INCLUDED_)
.cpp文件:
// AddCategDlg.cpp : implementation file
//#include "stdafx.h"
#include "MyMFCODBCSmpl.h"
#include "AddCategDlg.h"
#include "MainFrm.h"
#include "CategorySet.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CAddCategDlg dialog
CAddCategDlg::CAddCategDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAddCategDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddCategDlg)
m_strName = _T("");
m_strNote = _T("");
//}}AFX_DATA_INIT
}
void CAddCategDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddCategDlg)
DDX_Text(pDX, IDC_CATEG_NAME, m_strName);
DDX_Text(pDX, IDC_CATEG_NOTE, m_strNote);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddCategDlg, CDialog)
//{{AFX_MSG_MAP(CAddCategDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CAddCategDlg message handlersvoid CAddCategDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}int CAddCategDlg::WriteData()
{
int n Ret=-1;
if(m_strName.IsEmpty())
{
AfxMessageBox("产品分类名称不能为空!");
return nRet;
}
CDatabase db;
if(!db.Open(_T("MyNWind")))
{
AfxMessageBox("数据源连接失败!");
return nRet;
}
if(!db.BeginTrans())
return nRet;
TRY
{
CString strSql="Insert into Categories(CategoryName,Description) values(";
CString strTemp;
strTemp=m_strName;
strSql+="'";
strSql+=strTemp;
strSql+="'";
strSql+=",";
strSql+="'";
strTemp=m_strNote;
strSql+="'";
strSql+=")";
db.ExecuteSQL(strSql);
db.CommitTrans();
}
CATCH(CDBException,e)
{
db.Rollback();
AfxMessageBox(e->m_strError);
e->Delete();
return nRet;
}
END_CATCH;
CCategorySet *pSet=new CCategorySet(&db);
if(!pSet->IsOpen())pSet->Open();
pSet->m_strSort="ASC CategoryID";
pSet->MoveLast();
nRet=pSet->m_CategoryID;
pSet->Close();
delete pSet;
db.Close();
return nRet;
}
#define AFX_CATEGORYSET_H__CFCF419B_161E_45B8_BDBC_367EA1A87A85__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CategorySet.h : header file
///////////////////////////////////////////////////////////////////////////////
// CCategorySet recordsetclass CCategorySet : public CRecordset
{
public:
CCategorySet(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CCategorySet)// Field/Param Data
//{{AFX_FIELD(CCategorySet, CRecordset)
long m_CategoryID;
CString m_CategoryName;
CString m_Description;
CLongBinary m_Picture;
//}}AFX_FIELD
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCategorySet)
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;
.h文件
#endif
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CATEGORYSET_H__CFCF419B_161E_45B8_BDBC_367EA1A87A85__INCLUDED_)
.cpp文件:
// CategorySet.cpp : implementation file
//#include "stdafx.h"
#include "MyMFCODBCSmpl.h"
#include "CategorySet.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CCategorySetIMPLEMENT_DYNAMIC(CCategorySet, CRecordset)CCategorySet::CCategorySet(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CCategorySet)
m_CategoryID = 0;
m_CategoryName = _T("");
m_Description = _T("");
m_nFields = 4;
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
}
CString CCategorySet::GetDefaultConnect()
{
return _T("ODBC;DSN=MyNWind");
}CString CCategorySet::GetDefaultSQL()
{
return _T("[dbo].[Categories]");
}void CCategorySet::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CCategorySet)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Long(pFX, _T("[CategoryID]"), m_CategoryID);
RFX_Text(pFX, _T("[CategoryName]"), m_CategoryName);
RFX_Text(pFX, _T("[Description]"), m_Description);
RFX_LongBinary(pFX, _T("[Picture]"), m_Picture);
//}}AFX_FIELD_MAP
}/////////////////////////////////////////////////////////////////////////////
// CCategorySet diagnostics#ifdef _DEBUG
void CCategorySet::AssertValid() const
{
CRecordset::AssertValid();
}void CCategorySet::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
#endif //_DEBUG
是没有错的,将程序发给我吧
[email protected]