您的位置:首页 > 数据库

数据库及界面跳转携带变量

2014-03-29 20:42 323 查看
UpdateData();
  CoInitialize(NULL);
  _ConnectionPtr pConn(__uuidof(Connection));
  _RecordsetPtr pRst(__uuidof(Recordset));
 
  pConn->ConnectionString ="Provider=SQLOLEDB.1;Password=12345sa12345;Persist Security Info=True;User ID=sa;Initial Catalog=DBLAB;Data Source=STAR-PC;";
  pConn->Open ("","","",adConnectUnspecified);

     //cstring.format
     CString str = "select * from dbo.userinfo where userName = '";
     str += m_name;
     str += "' and userPwd = '";
     str +=  m_pw;
     str +=  "'";
     //_bstr_t pipei = (_bstr_t)str;
    
     //pRst=pConn->Execute(pipei,NULL,adCmdText);
     pRst=pConn->Execute((_bstr_t)str,NULL,adCmdText);
    
     if(!pRst->rsEOF)//pRst->rsEOF的值判定是否到达结尾,到达则为真,未到达则为假
     {
          CDialog::OnOK();
          CIndex dlg;
          dlg.m_whose = "当前登录用户为:" + m_name;
          dlg.DoModal();
     }
     else
          MessageBox("登录失败!");
    
     pRst->Close();
     pConn->Close();
     pRst.Release();
     pConn.Release();
     CoUninitialize();


涉及取SQL的内容,如下:

CoInitialize(NULL);
  _ConnectionPtr pConn(__uuidof(Connection));
  _RecordsetPtr pRst(__uuidof(Recordset));
  
  pConn->ConnectionString ="Provider=SQLOLEDB.1;Password=12345sa12345;Persist Security Info=True;User ID=sa;Initial Catalog=TestData1;Data Source=localhost;";
  pConn->Open ("","","",adConnectUnspecified);

  pRst=pConn->Execute("select * from  dbo.Products ",NULL,adCmdText);
  
  while(!pRst->rsEOF)
  {
		_bstr_t lpcstrlxx = (_bstr_t)pRst->GetCollect ("ProductName");//pRst->GetCollect强制为_bstr_t	
        ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(lpcstrlxx);
		//((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect ("ProductName"));
		_bstr_t strb = (_bstr_t)pRst->GetCollect ("ProductName");
		CString strlxx = (LPCTSTR)strb;
		MessageBox(strlxx);
		pRst->MoveNext ();
  }
  CString stre1 = "e2";
  CString strInsert1 = "insert into dbo.Products (ProductID,ProductName,Price) values ('727','";
  strInsert1 += stre1;
  strInsert1 += "','2303')";
  _bstr_t Insert1 = (_bstr_t)strInsert1;//ProductID是主键,不能重复,会奔溃!
  pConn->Execute(Insert1,NULL,adCmdText);
	MessageBox("yes!");
  pRst->Close ();

  pConn->Close ();
  pRst.Release ();
  pConn.Release ();
  CoUninitialize();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: