回 帖 发 新 帖 刷新版面

主题:请高手帮我看看错在哪儿啊,谢谢先

是这样,我现在有个字段用的int型,可是在对数据库操作时,连到这个变量上的vc控件变成long型,但是要插入一个新数据就是cstring类型,出现不匹配,怎么办呢

// 数据库View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "数据库.h"

#include "数据库Set.h"
#include "数据库Doc.h"
#include "数据库View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CRecordView)

BEGIN_MESSAGE_MAP(CMyView, CRecordView)
    //{{AFX_MSG_MAP(CMyView)
    ON_BN_CLICKED(IDC_OK, OnOk)
    ON_BN_CLICKED(IDC_CANCEL, OnCancel)
    ON_BN_CLICKED(IDC_ADD, OnAdd)
    ON_BN_CLICKED(IDC_NOADD, OnNoadd)
    ON_COMMAND(ID_RECORD_APPEND, OnRecordAppend)
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
    : CRecordView(CMyView::IDD)
{
    //{{AFX_DATA_INIT(CMyView)
    m_pSet = NULL;
    //}}AFX_DATA_INIT
    // TODO: add construction code here

}

CMyView::~CMyView()
{
}

void CMyView::DoDataExchange(CDataExchange* pDX)
{
    CRecordView::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMyView)
    DDX_Control(pDX, IDC_MONTH, m_month1);
    DDX_Control(pDX, IDC_SUBSIDE, m_subside1);
    DDX_Control(pDX, IDC_SCHOOL, m_school1);
    DDX_Control(pDX, IDC_SALARY, m_salary1);
    DDX_Control(pDX, IDC_AMOUNT, m_amont1);
    DDX_Control(pDX, IDC_NOADD, m_Noadd);
    DDX_Control(pDX, IDC_ADD, m_Add);
    DDX_FieldText(pDX, IDC_SALARY, m_pSet->m_salary, m_pSet);
    DDX_FieldText(pDX, IDC_SCHOOL, m_pSet->m_school, m_pSet);
    DDX_FieldText(pDX, IDC_SUBSIDE, m_pSet->m_subside, m_pSet);
    DDX_FieldText(pDX, IDC_AMOUNT, m_pSet->m_amount, m_pSet);
    DDX_FieldText(pDX, IDC_MONTH, m_pSet->m_month, m_pSet);
    //}}AFX_DATA_MAP
}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    return CRecordView::PreCreateWindow(cs);
}

void CMyView::OnInitialUpdate()
{
    m_pSet = &GetDocument()->m_mySet;
    CRecordView::OnInitialUpdate();
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
    // default preparation
    return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
    CRecordView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
    CRecordView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
    return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView database support
CRecordset* CMyView::OnGetRecordset()
{
    return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

void CMyView::OnOk()
{
    // TODO: Add your control notification handler code here
    MessageBox("努力赚钱,努力学习!");
    //CDialog::OnOK();

}

void CMyView::OnCancel()
{
    // TODO: Add your control notification handler code here
    MessageBox("不然我就去找帅哥哥,哈哈!");
}

void CMyView::OnAdd()
{
    // TODO: Add your control notification handler code here
    CString cValue;
    BOOL lNew=TRUE;
    m_month1.SetWindowText(cValue);
    
    m_pSet->MoveFirst();
    while(!m_pSet->IsEOF()^!lNew)
    {
        if(cValue==m_pSet->m_month)
            lNew=FALSE;
        m_pSet->MoveNext();
    }
    m_pSet->AddNew();

    m_month1.GetWindowText(cValue);
    m_pSet->m_month=cValue;
    m_school1.GetWindowText(cValue);
    m_pSet->m_school=cValue;
    m_subside1.GetWindowText(cValue);
    m_pSet->m_subside=cValue;
    m_salary1.GetWindowText(cValue);
    m_pSet->m_salary=cValue;

    m_pSet->Update();
    m_pSet->MoveLast();

    m_Add.ShowWindow(SW_HIDE);
    m_Noadd.ShowWindow(SW_HIDE);
}

void CMyView::OnNoadd()
{
    // TODO: Add your control notification handler code here
    m_Add.ShowWindow(SW_HIDE);
    m_Noadd.ShowWindow(SW_HIDE);
    m_month1.SetWindowText(m_pSet->m_month);
    m_salary1.SetWindowText(m_pSet->m_salary);
    m_school1.SetWindowText(m_pSet->m_school);
    m_subside1.SetWindowText(m_pSet->m_subside);
}

void CMyView::OnRecordAppend()
{
    // TODO: Add your command handler code here
    m_Add.SetWindowText("添加");
    m_Noadd.SetWindowText("取消");
    m_month1.SetWindowText("");
    m_salary1.SetWindowText("");
    m_school1.SetWindowText("");
    m_subside1.SetWindowText("");
}


数据库View.cpp
D:\课题\练习程序\数据库\数据库View.cpp(164) : warning C4244: 'argument' : conversion from 'long' to 'char', possible loss of data
D:\课题\练习程序\数据库\数据库View.cpp(171) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
D:\课题\练习程序\数据库\数据库View.cpp(191) : error C2664: 'SetWindowTextA' : cannot convert parameter 1 from 'long' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

数据库View.obj - 2 error(s), 1 warning(s)

回复列表 (共2个回复)

沙发

为什么没有人回复呢,55555555555

板凳

太长了!!!

我来回复

您尚未登录,请登录后再回复。点此登录或注册