在vc里获得系统时间 和其他1些信息 往sql server 2000数据库里写
怎么才能实现的代码和步骤 谢谢

解决方案 »

  1.   

    UpdateData();
    HRESULT hRe;
    char buf[200];
    _variant_t   theValue;//操作数据库所必用的类型
           try
    {

    connDB();
    memset(buf,0,sizeof(buf));
    strcpy(buf,"select pjid from PJ_DATE");
    hRe=rs->Open(_variant_t(buf),pConn.GetInterfacePtr(),adOpenForwardOnly,adLockReadOnly,adCmdText);
    memcpy(gadpjid,(const char*)(_bstr_t)(_variant_t)rs->GetCollect("pjid").bstrVal,sizeof(gadpjid));
            m_listpj.SetItemText(1,1,gadpjid);
    } catch(_com_error &e)
    {
    char buf[200];
    memset(buf,0,200);
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);  
    //AddLogInfo(buf);
    rs->Close();
    pConn->Close();
    return ;
      }
    }void CSetPJDlg::connDB()
    { HRESULT      hRe;      //定义一个用于获取返回值的句柄
    char    strconn[1024];//定义一个连接字符串
    hRe=pConn.CreateInstance(__uuidof(Connection));//建立数据库连接实例
    if(FAILED(hRe))
    {
    AfxMessageBox("创建数据库连接失败!");
    return ;
    } hRe=rs.CreateInstance(__uuidof(Recordset)); //建立纪录集实例
    if(FAILED(hRe))
    {
    pConn->Close();
    AfxMessageBox("创建纪录集失败!");
    return ;
    }
    try
    {
    HMODULE hmodule;
    int len;
    char gExename[256];
    memset(gExename,0,sizeof(gExename));
    hmodule=GetModuleHandle("syecc_pj.exe");
    len=GetModuleFileName(hmodule,gExename,256);
    gExename[len-12]=0;
    strcat(gExename,"config.ini");
    char sserver[20],sdatabase[20],suid[50],spwd[50];
    memset(sserver,0,sizeof(sserver));
    memset(sdatabase,0,sizeof(sdatabase));
    memset(suid,0,sizeof(suid));
    memset(spwd,0,sizeof(spwd)); GetPrivateProfileString("database","servername","",sserver,sizeof(sserver),gExename);
    GetPrivateProfileString("database","database","",sdatabase,sizeof(sdatabase),gExename);
    GetPrivateProfileString("database","logId","",suid,sizeof(suid),gExename);
    GetPrivateProfileString("database","logpass","",spwd,sizeof(spwd),gExename);
    sprintf(strconn,"Driver={SQL Server};Server=%s;Database=%s;Uid=%s;Pwd=%s;",sserver,sdatabase,suid,spwd);// strcpy(strconn,"Driver={SQL Server};Server=yhm;Database=pj1022;;Uid=sa;Pwd=123465;");
    _bstr_t strCnn(strconn); //用数据库连接字符串初始化_bstr_t类对象strCnn
    hRe=pConn->Open(strCnn,suid,spwd,-1);
    if(FAILED(hRe))
    {
    AfxMessageBox("连接数据库失败!");
    return ;
    }
    }
    catch(_com_error &e)
    {
    char buf[200];
    memset(buf,0,200);
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);  
    //AddLogInfo(buf);
    // rs->Close();
    pConn->Close();
    return ;
      }
    }