我写的数据库连接程序 一个登陆程序呀>
   可是不知道怎么办? 我第一次 连接 问题是没有老师呀 
 所以请大哥们 大姐们 帮帮忙把 extern CCzyxxb ffxxb;自己定义了一个外部变量
void CLogin::OnOK() 
{
// TODO: Add extra validation here
UpdateData(true);
if(m_name=="")
{
MessageBox("请输入用户名");
return;
}
if(ffxxb.HaveCzy(m_name,m_pwd)!=1)
{
MessageBox("用户密码错误!");
}
ffxxb.SetCzyName(m_name);
CString jb="1";
if(ffxxb.HaveCzyjb(m_name,m_pwd,jb)==1)
{
ffxxb.SetCzyjb(jb);
}
CDialog::OnOK();
}int CCzyxxb::HaveCzy(CString cName,CString cPwd)
{
  ADOConn m_AdoConn;
  CString vSQL;
  vSQL="SELECT * FROM Czyxxb WHERE CzyName='"+cName+"' and Pwd='"+cPwd+"' ";
  _RecordsetPtr m_pRecordset;
   m_pRecordset=m_AdoConn.ExecuteSQL((_bstr_t)vSQL);//这快异常处理拉 我都不知道怎么办? 
  if(m_pRecordset->adoEOF)
   return -1;
  else
return 1;
  m_AdoConn.ExitConnect();
}
void ADOConn::OnInitADOConn()
{
HRESULT hr; 
    ::CoInitialize(NULL);
    try{
hr=m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
        { 
      _bstr_t  strConnect="Provider=SQLOLEDB.1;Persist Security Info=false;Initial Catalog=GZFFXT;Date Source=.";
   m_pConnection->Open(strConnect,"sa","123",-1);
         //  AfxMessageBox("连接数据库 "+m_pConnection->GetConnectionString());
        } }catch(_com_error e)
{
       CString temp; 
       temp.Format("连接数据库错误信息:%s",e.ErrorMessage()); 
       ::MessageBox(NULL,temp,"提示信息",NULL); 
       AfxMessageBox(e.Source()); 
       AfxMessageBox(e.Description()); 
}}
BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)
{ try
{
  if(m_pConnection==NULL)
  {
  OnInitADOConn();
  } 
            m_pConnection->Execute((_bstr_t)bstrSQL,NULL,adCmdText);
return true;
}
    catch(_com_error e)
{
     AfxMessageBox(e.Description());
      return false;
}}重分感谢它 在线等 !!! 最好把改好的代码 贴上去 HELP ME!!!

解决方案 »

  1.   

    你要表达什么呢?没看懂extern CCzyxxb ffxxb;自己定义了一个外部变量 
    void CLogin::OnOK() 

    // TODO: Add extra validation here 
    UpdateData(true); 
    if(m_name=="") 

    MessageBox("请输入用户名"); 
    return; 

    if(ffxxb.HaveCzy(m_name,m_pwd)!=1) 

    MessageBox("用户密码错误!"); 

    ffxxb.SetCzyName(m_name); 
    CString jb="1"; 
    if(ffxxb.HaveCzyjb(m_name,m_pwd,jb)==1) 

    ffxxb.SetCzyjb(jb); 

    CDialog::OnOK(); 
    } int CCzyxxb::HaveCzy(CString cName,CString cPwd) 

      ADOConn m_AdoConn; 
      CString vSQL; 
      vSQL="SELECT * FROM Czyxxb WHERE CzyName='"+cName+"' and Pwd='"+cPwd+"' "; 
      _RecordsetPtr m_pRecordset; 
      m_pRecordset=m_AdoConn.ExecuteSQL((_bstr_t)vSQL);//这快异常处理拉 我都不知道怎么办? 
      if(m_pRecordset->adoEOF) 
      return -1; 
      else 
    return 1; 
      m_AdoConn.ExitConnect(); 

    void ADOConn::OnInitADOConn() 

    HRESULT hr; 
        ::CoInitialize(NULL); 
        try{ 
    hr=m_pConnection.CreateInstance("ADODB.Connection"); 
    if (SUCCEEDED(hr)) 
            { 
          _bstr_t  strConnect="Provider=SQLOLEDB.1;Persist Security Info=false;Initial Catalog=GZFFXT;Date Source=."; 
      m_pConnection->Open(strConnect,"sa","123",-1); 
            //  AfxMessageBox("连接数据库 "+m_pConnection->GetConnectionString()); 
            } }catch(_com_error e) 

          CString temp; 
          temp.Format("连接数据库错误信息:%s",e.ErrorMessage()); 
          ::MessageBox(NULL,temp,"提示信息",NULL); 
          AfxMessageBox(e.Source()); 
          AfxMessageBox(e.Description()); 
    } } 
    BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL) 
    { try 

      if(m_pConnection==NULL) 
      { 
      OnInitADOConn(); 
      } 
                m_pConnection->Execute((_bstr_t)bstrSQL,NULL,adCmdText); 
    return true; 

        catch(_com_error e) 

        AfxMessageBox(e.Description()); 
        return false; 
    } } 
      

  2.   

    我只要判断表内 是否有我的数据呀 
        然后就可以拉 
      我单步调的是到这m_pRecordset=m_AdoConn.ExecuteSQL((_bstr_t)vSQL); 就不去拉 
      我也不知道 怎么办 
      最好帮我写一个也可以拉我 
    _bstr_t  strConnect="Provider=SQLOLEDB.1;Persist Security Info=false;Initial Catalog=GZFFXT;Date Source=."; 
      m_pConnection->Open(strConnect,"sa","123",-1); 这样写可以吗?
      

  3.   

    你ExecuteSQL是BOOL类型的,怎么出了这么一句?m_pRecordset=m_AdoConn.ExecuteSQL((_bstr_t)vSQL);
      

  4.   

    改成这样试试_RecordsetPtr ADOConn::ExecuteSQL(_bstr_t bstrSQL) 
    { try 

      if(m_pConnection==NULL) 
      { 
      OnInitADOConn(); 
      } 
      return   m_pConnection->Execute((_bstr_t)bstrSQL,NULL,adCmdText); 
     

    catch(_com_error e) 

        AfxMessageBox(e.Description()); 
        return false; 
    } } 
      

  5.   

    不不过它说 内河32.DLL 错误拉
       runtime错误