如题所示,例如一个SqlServer数据库中有三个表,分别是A、B、C,现在我已经将A表连接好了,怎么样继续连接B表和C表??

解决方案 »

  1.   

    我是这样连接数据库的:
    m_strConnection=_T("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;
         Password=00;Initial Catalog=LunDuiTest;Data Source=rongbing;
         Use Procedure for  Prepare=1;Auto Translate=True;Packet Size=4096;
         Workstation ID=rongbing;");
    m_strCmdText=_T("select * from  A"); m_pRs=NULL; 
    m_piAdoRecordBinding=NULL;
    ::CoInitialize(NULL);
    如果连接B表,是不是这样呢?
    m_strCmdText=_T("select * from  B");
      

  2.   

    看你的连接方式,完全可以连接数据库之后通过sql语句去打开不同的表
      

  3.   

    我用的是ADORecordBinding 邦定的数据库
      

  4.   

    // 添加一个指向Connection对象的指针
    _ConnectionPtr m_pConnection;
    //连接SQL Server数据库的字符串
    _bstr_t strConnect = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=123;Initial Catalog=mydb;Data Source=(local)";
    //执行数据连接
    m_pConnection->Open((_bstr_t)strConnectSQL,"","",adModeUnknown);// 执行SQL语句,Insert Update _variant_t
    BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)
    {
             //_variant_t RecordsAffected;
    try
    {
    // 是否已经连接数据库
    if(m_pConnection == NULL)
    OnInitADOConn();
    // Connection对象的Execute方法:(_bstr_t CommandText, 
    // VARIANT * RecordsAffected, long Options ) 
    // 其中CommandText是命令字串,通常是SQL命令。
    // 参数RecordsAffected是操作完成后所影响的行数, 
    // 参数Options表示CommandText的类型:adCmdText-文本命令;adCmdTable-表名
    // adCmdProc-存储过程;adCmdUnknown-未知
    m_pConnection->Execute(bstrSQL,NULL,adCmdText);
    return true;
    }
    catch(_com_error e)
    {
    AfxMessageBox(e.Description());
    return false;
    }
    }// 执行查询
    _RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
    {
    //TODO: return statement
    try
    {
    // 连接数据库,如果Connection对象为空,则重新连接数据库
    if(m_pConnection==NULL)
    OnInitADOConn();
    // 创建记录集对象
    m_pRecordset.CreateInstance(__uuidof(Recordset));
    // 取得表中的记录
    m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
    }
    // 捕捉异常
    catch(_com_error e)
    {
    // 显示错误信息
    AfxMessageBox(e.Description());
    }
    // 返回记录集
    return m_pRecordset;
    }
      

  5.   

    回复人:rongbing77() ( 一级(初级)) 信誉:100  2006-10-23 11:39:18  得分:0
    ?  我是这样连接数据库的:
    m_strConnection=_T("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;
    Password=00;Initial Catalog=LunDuiTest;Data Source=rongbing;
    Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;
    Workstation ID=rongbing;");
    m_strCmdText=_T("select * from A");m_pRs=NULL;
    m_piAdoRecordBinding=NULL;
    ::CoInitialize(NULL);
    如果连接B表,是不是这样呢?
    m_strCmdText=_T("select * from B");是