hehe

hehe

0个粉丝

4

问答

0

专栏

2

资料

hehe  发布于  2008-08-04 23:22:43
采纳率 0%
4个问答
4716

ADO2操作数据库代码

   
[code]// ADO2.cpp: implementation of the CADO class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DataBase.h"
#include "ADO2.h"
#include

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

extern CListCtrl m_output_list;
extern int key_flag;
extern _ConnectionPtr m_pConnection;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CADO::CADO()
{

}

CADO::~CADO()
{

}
bool CADO::AddBom(CString *aa,int num,CString bb)
{
        _variant_t var;
        CString str;
        _RecordsetPtr        myset=NULL;
        _RecordsetPtr m_pRecordset;
        CString sql;
        int i;
       
    m_pRecordset = OpenBom();
       
        sql.Format("SELECT * FROM BomTable where "+bb+"='%s'"\
                ,aa[0]);
       
        myset=m_pConnection->Execute(_bstr_t(sql),NULL,adCmdText);
       
        if(myset->BOF)
        {
                m_pRecordset->AddNew();
                for(i=0;i                 {                       
                        m_pRecordset->PutCollect(_variant_t(long(i)),_variant_t(aa));                       
                }
                m_pRecordset->Update();
               
                AfxMessageBox("插入成功!");
               
                return TRUE;
        }
        else
        {
                return FALSE;
        }
}

void CADO::DisplayBom(_RecordsetPtr m_pRecordset,int num)
{
        int k=0;
        int i;
        _variant_t var;
        CString   str[15];
       
        m_output_list.DeleteAllItems();
       
        while(!m_pRecordset->adoEOF)
        {               
                m_output_list.InsertItem(k,"");
               
                for(i=0;i                 {
                        var = m_pRecordset->GetCollect(_variant_t((long)i));
                        if(var.vt != VT_NULL)
                                str = (LPCSTR)_bstr_t(var);
                        m_output_list.SetItemText(k,i,(LPCSTR)str);
                }
               
                k++;
                m_pRecordset->MoveNext();
        }
       
}

_RecordsetPtr CADO::OpenBom()
{
                m_pRecordsetBom.CreateInstance(__uuidof(Recordset));
                 
                 // 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
                 // 因为它有时会经常出现一些意想不到的错误。jingzhou xu
                 try
                 {
                         m_pRecordsetBom->Open("SELECT * FROM ContractTable",                // 查询BomTable表中所有字段
                                 m_pConnection.GetInterfacePtr(),         // 获取库接库的IDispatch指针
                                 adOpenDynamic,
                                 adLockOptimistic,
                                 adCmdText);
                 }
                 catch(_com_error *e)
                 {
                         AfxMessageBox(e->ErrorMessage());
                 }   
    return m_pRecordsetBom;
}

_RecordsetPtr CADO::FindBom(int flag,CString *aa,CString *s,int num)
{
        _variant_t var;
        CString str;
        _RecordsetPtr        myset=NULL;
        _RecordsetPtr m_pRecordset;
        CString sql;
        int i;
       
    m_pRecordset = OpenBom();
       
        for ( i=1;i         {
                if (flag == i)
                {       
                        if (aa[i-1]  == "")
                        {
                                AfxMessageBox(""+s[i-1]+"不能为空!");
                                return NULL;
                        }
                        else
                        {               
                                sql.Format("SELECT * FROM BomTable where "+s[i-1]+"='%s'"\
                                        ,aa[i-1]);
                        }
                        break;
                }       
        }
       
    if( i == num+1)
        {
                AfxMessageBox("请先选择查找项!");
                return NULL;
        }
       
        myset=m_pConnection->Execute(_bstr_t(sql),NULL,adCmdText);
       
        return myset;
       
}


bool CADO::modiBom(CString *aa,int num,CString bb)
{       
        _variant_t var;
        CString str;
        _RecordsetPtr m_pRecordset;
        int i;
       
        m_pRecordset = OpenBom();
       
        m_pRecordset->MoveFirst();
    while(1)
        {
                var= m_pRecordset->GetCollect(_variant_t((long)0));
                str=(LPCSTR)_bstr_t(var);
        if(strcmp(aa[0],str))
                        m_pRecordset->MoveNext();
                else break;
        }
       
        for(i=1;i         {
                m_pRecordset->PutCollect(_variant_t((long)i),_variant_t(aa));
        }
        m_pRecordset->Update();
       
        m_pRecordset->Close();
        m_pRecordset = NULL;
        return TRUE;
       
}

bool CADO::DelBom(CString Bom_num)
{
        _variant_t var;
        CString str;
   _RecordsetPtr m_pRecordset;

        m_pRecordset = OpenBom();
        m_pRecordset->MoveFirst();
    while(1)
        {
                var= m_pRecordset->GetCollect(_variant_t((long)0));
                str=(LPCSTR)_bstr_t(var);
        if(strcmp(Bom_num,str))
                        m_pRecordset->MoveNext();
                else break;
        }
    m_pRecordset->Delete(adAffectCurrent);  // 参数adAffectCurrent为删除当前记录
    m_pRecordset->Update();

        m_pRecordset->Close();
        m_pRecordset = NULL;
       
        return TRUE;
}

void CADO::LeadInBom(CString *p,int n,CString *s,int num)
{
        int count;
        int i,j;
        int a[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        int        b[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        CString *q;
        _variant_t var;
        CString str[20];
        _RecordsetPtr        myset=NULL;
        _RecordsetPtr m_pRecordset;
        CString sql;
       
        count = m_output_list.GetItemCount();
        if (count<0)
                AfxMessageBox("ERROR");

       
        for(i=0;i         {
                q=p;
                for(j=0;j                 {
                        if(!strcmp(s,*(q++)))
                        {
                                a=1;b=j;
                                break;
                        }
                }
        }
  
        for(i=0;i         {
                for(j=0;j                 {
                        if(a[j]==1)
                        {
                                var=m_output_list.GetItemText(i,b[j]);       
                                if(var.vt != VT_NULL)
                                        str[j] = (LPCSTR)_bstr_t(var);
                        }
                }
       
        if (str[0] != "")
                {
                        m_pRecordset = OpenBom();
                       
                        sql.Format("SELECT * FROM BomTable where "+s[0]+"='%s'"\
                                ,str[0]);
                       
                        myset=m_pConnection->Execute(_bstr_t(sql),NULL,adCmdText);
                       
                        if(myset->BOF)
                        {
                                m_pRecordset->AddNew();
                                for(i=0;i                                 {
                                        m_pRecordset->PutCollect(_variant_t((long)i),_variant_t(str));
                                }
                                m_pRecordset->Update();
                               
                        }

                }
        }

}

void CADO::DelAllBom()
{
        _RecordsetPtr m_pRecordset;

        m_pRecordset = OpenBom();
       
        if(!m_pRecordset->BOF)
        {
               
                m_pRecordset->MoveFirst(); // 从0开始
                while (m_pRecordset->GetadoEOF()!=VARIANT_TRUE)
                {
                       
                       
                        m_pRecordset->Delete(adAffectCurrent);  // 参数adAffectCurrent为删除当前记录
                        m_pRecordset->Update();
                        m_pRecordset->MoveFirst(); // 从0开始
                       
                }
        }

}[/code]
我来回答
回答0个
时间排序
认可量排序
易百纳技术社区暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区