文件名称:读取员工信息-在VC中使用ADO实例
文件大小:265KB
文件格式:PPT
更新时间:2024-05-15 13:18:24
VC ADO
读取员工信息 void CEmployees::GetData(CString cEmpId) { ADOConn m_AdoConn; //连接数据库 m_AdoConn.OnInitADOConn(); _bstr_t vSQL; //设置SELECT语句 vSQL = "SELECT * FROM Employees WHERE Emp_id=" + cEmpId; _RecordsetPtr m_pRecordset; //执行SELETE语句 m_pRecordset = m_AdoConn.GetRecordSet(vSQL); if (m_pRecordset->adoEOF == 1) //返回各列的值 CEmployees(); else { Emp_id = atoi(cEmpId); Emp_name = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Emp_Name"); Sex = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sex"); Title = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Title"); Wage = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Wage")); Dep_id = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Dep_id")); }//断开与数据库的连接 m_AdoConn.ExitConnect(); }