| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 353 人关注过本帖, 1 人收藏
标题:帮忙请教VC6.0编写的ADO+ACCESS毕业设计部分功能运行不成功的问题
只看楼主 加入收藏
sad4474
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
结帖率:100%
收藏(1)
 问题点数:0 回复次数:0 
帮忙请教VC6.0编写的ADO+ACCESS毕业设计部分功能运行不成功的问题
程序代码:
下面的程序是论坛找的ADO连接数据库的程序,被我改了。因为当初论坛发的是只有一个对话框的。我现在改成由对话框弹出另外的对话框,在由另外的对话框显示的ADO数据库操作
但问题是现在按原来但对话框操作的程序,现在又多对话框弹出后,其中的删除,增加,修改这3个功能都错误,点了后会程序出错。请教是怎么回事?
#if !defined(AFX_DIALOG1_H__F81D8FBB_B749_4E98_98B5_F689C9656ED7__INCLUDED_)
#define AFX_DIALOG1_H__F81D8FBB_B749_4E98_98B5_F689C9656ED7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DIALOG1.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CDIALOG1 dialog

class CDIALOG1 : public CDialog
{
// Construction

public:
    CDIALOG1(CWnd* pParent = NULL);   // standard constructor
public:
    _ConnectionPtr  m_pConn;
    _RecordsetPtr     m_pRst;
    _CommandPtr    m_pCmd;

// Dialog Data
    //{{AFX_DATA(CDIALOG1)
    enum { IDD = IDD_DIALOG1 };
    CListBox    m_list;
    CString    m_ID;
    CString    m_riqi;
    CString    m_banbie;
    CString    m_renyuan;
    CString    m_guzhangyuanyin;
    CString    m_chulifangshi;
    CString    m_shiyongzhuangtai;
    CString    m_guzhangcishu;
    CString    m_lutibianhao;
    virtual BOOL OnInitDialog();//重点这里增加了个函数定义,没有这个调试不出
    //}}AFX_DATA


// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDIALOG1)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    HICON m_hIcon;

    // Generated message map functions
    //{{AFX_MSG(CDIALOG1)
    afx_msg void OnButton46();
    afx_msg void OnButton47();
    afx_msg void OnButton48();
    afx_msg void OnButton49();
    afx_msg void OnButton50();
    afx_msg void OnSelchangeList1();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DIALOG1_H__F81D8FBB_B749_4E98_98B5_F689C9656ED7__INCLUDED_)

// DIALOG1.cpp : implementation file
//

#include "stdafx.h"
#include "lunwen.h"
#include "DIALOG1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDIALOG1 dialog


CDIALOG1::CDIALOG1(CWnd* pParent /*=NULL*/)
    : CDialog(CDIALOG1::IDD, pParent)
{
    //{{AFX_DATA_INIT(CDIALOG1)
    m_ID = _T("");
    m_riqi = _T("");
    m_banbie = _T("");
    m_renyuan = _T("");
    m_guzhangyuanyin = _T("");
    m_chulifangshi = _T("");
    m_shiyongzhuangtai = _T("");
    m_guzhangcishu = _T("");
    m_lutibianhao = _T("");
    //}}AFX_DATA_INIT
}


void CDIALOG1::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDIALOG1)
    DDX_Control(pDX, IDC_LIST1, m_list);
    DDX_Text(pDX, IDC_EDIT1, m_ID);
    DDX_Text(pDX, IDC_EDIT2, m_riqi);
    DDX_Text(pDX, IDC_EDIT3, m_banbie);
    DDX_Text(pDX, IDC_EDIT4, m_renyuan);
    DDX_Text(pDX, IDC_EDIT5, m_guzhangyuanyin);
    DDX_Text(pDX, IDC_EDIT6, m_chulifangshi);
    DDX_Text(pDX, IDC_EDIT7, m_shiyongzhuangtai);
    DDX_Text(pDX, IDC_EDIT8, m_guzhangcishu);
    DDX_Text(pDX, IDC_EDIT9, m_lutibianhao);
    //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDIALOG1, CDialog)
    //{{AFX_MSG_MAP(CDIALOG1)
    ON_BN_CLICKED(IDC_BUTTON46, OnButton46)
    ON_BN_CLICKED(IDC_BUTTON47, OnButton47)
    ON_BN_CLICKED(IDC_BUTTON48, OnButton48)
    ON_BN_CLICKED(IDC_BUTTON49, OnButton49)
    ON_BN_CLICKED(IDC_BUTTON50, OnButton50)
    ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDIALOG1 message handlers

BOOL CDIALOG1::OnInitDialog() //重点,增加的函数,把数据库连接写在这个函数里
{
    CDialog::OnInitDialog();
   
    // TODO: Add extra initialization here
    AfxOleInit();   //初始化Com接口,相当于CoInitialize(NULL) CoUninitialize();

    m_pCmd.CreateInstance(__uuidof(Command));                //初始化三个Com对象
    m_pConn.CreateInstance(__uuidof(Connection));
    m_pRst.CreateInstance(__uuidof(Recordset));

    try
    {
        m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=lunwen.mdb","","",adModeUnknown);  //用Connection连接对象打开数据库文件

    }
    catch(_com_error e)
    {
        MessageBox("打开数据库失败");
    }

    try
    {
        //将Connection对象打开的数据库与记录集RecordSet关联起来
        m_pRst->Open("select * from 钢包车故障记录",m_pConn.GetInterfacePtr(),adOpenDynamic,    adLockOptimistic,adCmdText);
    }
    catch(_com_error e)
    {
        MessageBox("连接对象与记录集对象管理失败失败");
    }
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

void CDIALOG1::OnButton46()
{
   
    // TODO: Add your control notification handler code here
    _variant_t  var;
   
    CString ID;
    CString riqi;
    CString banbie;
    CString renyuan;
    CString guzhangyuanyin;
    CString chulifangshi;
    CString shiyongzhuangtai;
    CString guzhangcishu;
    CString lutibianhao;

    m_pRst->MoveFirst();
    m_list.ResetContent();    //清除list列表中的内容
    

    while(!m_pRst->rsEOF)
    {
        var=m_pRst->GetCollect("ID");
        if(var.vt!=VT_NULL)
            ID=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("日期");
        if(var.vt!=VT_NULL)
            riqi=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("班别");
        if(var.vt!=VT_NULL)
            banbie=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("人员");
        if(var.vt!=VT_NULL)
            renyuan=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("故障原因");
        if(var.vt!=VT_NULL)
            guzhangyuanyin=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("处理方式");
        if(var.vt!=VT_NULL)
            chulifangshi=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("使用状态");
        if(var.vt!=VT_NULL)
            shiyongzhuangtai=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("故障次数");
        if(var.vt!=VT_NULL)
            guzhangcishu=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("炉体编号");
        if(var.vt!=VT_NULL)
            lutibianhao=(LPSTR)_bstr_t(var);

        m_list.AddString(ID+" "+banbie+" "+renyuan+" "+guzhangyuanyin+" "+chulifangshi+" "+shiyongzhuangtai+" "+guzhangcishu+" "+lutibianhao);

        m_pRst->MoveNext();
    }
   
}

void CDIALOG1::OnButton47()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);

    if (m_ID!=""&&m_banbie!=""&&m_renyuan!=0&&m_guzhangyuanyin!=""&&m_chulifangshi!=""&&m_shiyongzhuangtai!=""&&m_guzhangcishu!=""&&m_lutibianhao!="")
    {
        m_pRst->AddNew();
        m_pRst->PutCollect("ID",_variant_t(m_ID));
        m_pRst->PutCollect("班别",_variant_t(m_banbie));
        m_pRst->PutCollect("人员",_variant_t(m_renyuan));
        m_pRst->PutCollect("故障原因",_variant_t(m_guzhangyuanyin));
        m_pRst->PutCollect("处理方式",_variant_t(m_chulifangshi));
        m_pRst->PutCollect("使用状态",_variant_t(m_shiyongzhuangtai));
        m_pRst->PutCollect("故障次数",_variant_t(m_guzhangcishu));
        m_pRst->PutCollect("炉体编号",_variant_t(m_lutibianhao));
        m_pRst->Update();                //确认数据库已改变

        OnButton46();
    }

}

void CDIALOG1::OnButton48()
{
    // TODO: Add your control notification handler code here
    int index;
    UpdateData(TRUE);

    index=m_list.GetCurSel();

    if (index>=0&&m_ID!=""&&m_banbie!=""&&m_renyuan!=0&&m_guzhangyuanyin!=""&&m_chulifangshi!=""&&m_shiyongzhuangtai!=""&&m_guzhangcishu!=""&&m_lutibianhao!="")
    {
        

        m_pRst->PutCollect("ID",_variant_t(m_ID));
        m_pRst->PutCollect("班别",_variant_t(m_banbie));
        m_pRst->PutCollect("人员",_variant_t(m_renyuan));
        m_pRst->PutCollect("故障原因",_variant_t(m_guzhangyuanyin));
        m_pRst->PutCollect("处理方式",_variant_t(m_chulifangshi));
        m_pRst->PutCollect("使用状态",_variant_t(m_shiyongzhuangtai));
        m_pRst->PutCollect("故障次数",_variant_t(m_guzhangcishu));
        m_pRst->PutCollect("炉体编号",_variant_t(m_lutibianhao));
        m_pRst->Update();                //确认数据库已改变
       
        OnButton46();
    }
}

void CDIALOG1::OnButton49()
{
    // TODO: Add your control notification handler code here
    int index;
    UpdateData(TRUE);
   
    index=m_list.GetCurSel();
   
    if (index>=0&&m_ID!=""&&m_banbie!=""&&m_renyuan!=0&&m_guzhangyuanyin!=""&&m_chulifangshi!=""&&m_shiyongzhuangtai!=""&&m_guzhangcishu!=""&&m_lutibianhao!="")
    {
       
        m_pRst->Delete(adAffectCurrent);//删除当前记录
        m_pRst->Update();                //确认数据库已改变
       
        OnButton46();
    }
}

void CDIALOG1::OnButton50()
{
    // TODO: Add your control notification handler code here
    CDIALOG1::EndDialog(TRUE);
}

void CDIALOG1::OnSelchangeList1()
{
    // TODO: Add your control notification handler code here
    int index;
    _variant_t var;

    index=m_list.GetCurSel();        //获取当前点击项目编号

    m_pRst->MoveFirst();            //将数据库游标指向第一个
    m_pRst->Move(long(index));        //游标向下偏移index个

    var=m_pRst->GetCollect("ID");
        if(var.vt!=VT_NULL)
            m_ID=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("日期");
        if(var.vt!=VT_NULL)
            m_riqi=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("班别");
        if(var.vt!=VT_NULL)
            m_banbie=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("人员");
        if(var.vt!=VT_NULL)
            m_renyuan=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("故障原因");
        if(var.vt!=VT_NULL)
            m_guzhangyuanyin=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("处理方式");
        if(var.vt!=VT_NULL)
            m_chulifangshi=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("使用状态");
        if(var.vt!=VT_NULL)
            m_shiyongzhuangtai=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("故障次数");
        if(var.vt!=VT_NULL)
            m_guzhangcishu=(LPSTR)_bstr_t(var);

        var=m_pRst->GetCollect("炉体编号");
        if(var.vt!=VT_NULL)
            m_lutibianhao=(LPSTR)_bstr_t(var);
    UpdateData(FALSE);
}
搜索更多相关主题的帖子: 连接数据库 数据库操作 对话框 
2013-02-27 13:41
快速回复:帮忙请教VC6.0编写的ADO+ACCESS毕业设计部分功能运行不成功的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020290 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved