void CTypeManager::GetAllType(CList<CType,CType> *pLstType) { CAdoRecordSet set; set.SetAdoConnection(m_pConn); set.SetCursorLocation(); set.Open("TypeInfo",adCmdTable); CType type; while(!set.IsEOF()) { set.GetCollect("id",type.nTypeID); set.GetCollect("typeName",type.strTypeName); pLstType->AddTail(type); set.MoveNext(); } }
void CVideoManager::GetVideosByTypeID(long typeID,CList<CVideo,CVideo> *pLstVideo) { CString strSql; strSql.Format("select id,videoName from videoinfo where typeid=%d",typeID); CAdoRecordSet set; set.SetAdoConnection(m_pConn); set.SetCursorLocation(); set.Open(strSql); CVideo v; while(!set.IsEOF()) { set.GetCollect("id",v.nVideoID); set.GetCollect("videoName",v.strVideoName); pLstVideo->AddTail(v); set.MoveNext(); } }
void CDlg1::OnBnClickedButton7() { // TODO: 在此添加控件通知处理程序代码 CString sql = NULL;//SQL语句 CString bookID = NULL,readerID = NULL; CStringArray col; //得到输入的信息 GetDlgItem(IDC_EDIT1)->GetWindowText(readerID); GetDlgItem(IDC_EDIT3)->GetWindowText(bookID); //bookID.Format(_T("您输入的条码为:%s"),bookID);//不能自己调用自己又添加自己 //连接,登陆数据库的操作 adoConnect.ConnectSQLServer(_T("JJ_VAIO"),_T("LibraryDataBaseTest"),_T("testdatabase"),_T("123")); CAdoConnection *p = &adoConnect; adoRecSet.SetAdoConnection(p); adoCommand.SetCommandText(_T("insert into Users valuse('a','a','a','a','a',5)")); adoCommand.Execute(); //END 连接登陆数据库 //下面这一段没什么用 /*//下面试试给所有行的首列列添加数据——成功 for (int insertrow = 0;insertrow <4;insertrow++) { m_list_bookinfo.InsertItem(insertrow,_T(""));//插入一行 m_list_bookinfo.SetItemText(insertrow,0,col[insertrow]);//加入一行 }; //下面这些是成功的录入的,但是太麻烦了 for(int i = 0;i <4;i++) m_list_bookinfo.InsertItem(i,_T(""));//插入一行 //下面尝试用双循环给所有行所有列录入信息,外循决定列,内循环决定行 for(int insertcol = 0;insertcol <8;insertcol++)//外循环控制列输出 { //下面这个函数,游标恢复TOP位置的语句被注释掉了,我把它释放了,具体位置看书签 adoRecSet.GetFieldValues(&col,insertcol,FALSE,4);//从数据库取出第insertcol列 for (int insertrow = 0;insertrow <4;insertrow++)//内循环控制行输出 { m_list_bookinfo.SetItemText(insertrow,insertcol,col[insertrow]);// } } */ //下面这一段,实现了查询的功能 if( bookID.IsEmpty() || readerID.IsEmpty()) { MessageBox(_T("请输入读者ID和图书ID"),_T("提示")); } else { MessageBox(_T("输入的读者编号为:")+readerID+_T("\n输入的图书条码为:")+bookID); //第一步,查询图书ID,这里是有效代码(或许可以写成一个函数,和下边的合并,不过一次性写对的成功率不大,调试会浪费大部分时间) //曾经考虑过溢出问题,但是好像,一般数据规模还不会溢出,只是程序的资源占用很大 //下面对控件,记录集做初始化 m_list_bookinfo.DeleteAllItems();//清空ListCtrl里的内容 adoRecSet.Close();//关闭已经打开的记录集 //sql.Format(_T("select * from Books where BookID = '%s'"),bookID); sql.Format(_T("select * from Books where BookID > 0"));//本句测试当全部输出数据时内存会不会溢出 adoRecSet.Open(sql,adCmdText);//打开新的记录集 //下面这个以后可能还要优化,GetFieldValues()第一个参数不同可以针对不同的类型值取value for(int insertrow = 0;!adoRecSet.IsEOF();insertrow++) { m_list_bookinfo.InsertItem(insertrow,_T(""));//控件中插入行 //这里应该不需要把详细信息都输出,因为还有个书籍详细信息栏。 for(int insertcol = 0;insertcol < 9;insertcol++)//内循环控制列 { adoRecSet.GetFieldValues(&col,insertcol,FALSE,1);//数据库取出数据 m_list_bookinfo.SetItemText(insertrow,insertcol,col[0]); } adoRecSet.MoveNext(); } //END 查询图书ID //第二步,查询读者ID,这里是有效代码,或许可以写成一个函数 //清空ListCtrl里的内容;关闭已经打开的记录集,设置查询语句,再重新打开记录集 m_list_readerinfo.DeleteAllItems(); adoRecSet.Close(); //sql.Format(_T("select * from Users where UserID = '%s'"),readerID); sql.Format(_T("select * from Users"));//本句测试当全部输出数据时内存会不会溢出 adoRecSet.Open(sql,adCmdText); //下面这个以后可能还要优化,GetFieldValues()第一个参数不同可以针对不同的类型值取value for(int insertrow = 0;!adoRecSet.IsEOF();insertrow++) { //控件中插入行 m_list_readerinfo.InsertItem(insertrow,_T("")); //内循环控制列 for(int insertcol = 0;insertcol < 6;insertcol++) { //数据库取出数据 adoRecSet.GetFieldValues(&col,insertcol,FALSE,1); m_list_readerinfo.SetItemText(insertrow,insertcol,col[0]); } adoRecSet.MoveNext(); } //END 查询读者ID //第三步,填充图书基本信息栏—————— adoRecSet.Close();//关闭已经打开的记录集 sql.Format(_T("select * from Books where BookID = '%s'"),bookID); adoRecSet.Open(sql,adCmdText); for(int insertrow = 0;!adoRecSet.IsEOF();insertrow++) { for(int insertcol = 0;insertcol < 9;insertcol++)//内循环控制列 { adoRecSet.GetFieldValues(&col,insertcol,FALSE,1); switch(insertcol) { //m_barcodeinfo.SetWindowText(_T("小蝌蚪找妈妈"));//用这个语句给图书基本信息组里的框框赋值 case 0:m_barcodeinfo.SetWindowText(col[0]);break;//用这个语句给图书基本信息组里的框框赋值; case 1:m_isbn.SetWindowText(col[0]);break; case 2:m_bookname.SetWindowText(col[0]);break; case 3:m_publish.SetWindowText(col[0]);break; case 4:m_publishtime.SetWindowText(col[0]);break; case 5:m_writter.SetWindowText(col[0]);break; case 6:m_importtime.SetWindowText(col[0]);break; case 7:m_availiable.SetWindowText(col[0]);break; case 8:m_position.SetWindowText(col[0]);break; default:break; } } adoRecSet.MoveNext(); } } //END 填充图书基本信息栏 }