3.6.6 商品详细信息查询处理(2)

2013-10-07 14:50:32 · 作者: · 浏览: 71

3.6.6  商品详细信息查询处理(2)

上面的代码中实现了列表信息输出用SetList2Value()函数进行封装,具体代码如下:

代码位置:见光盘中本章源代码的CForeMange类。

  1. 1  void CForeMange::SetList2Value(CString sqlstr)  
  2. 2  {  
  3. 3   GetRecord(sqlstr);                                  //执行查询语句  
  4. 4   m_list2.DeleteAllItems();                               //列表控件数据清空  
  5. 5   int rows=0;  
  6. 6   try  
  7. 7   {  
  8. 8       for(int i=0;i<6;i++)  
  9. 9       {  
  10. 10              CString str;                                    //定义变量,保存结果  
  11. 11              str=(LPCSTR)(_bstr_t)m_record->Fields->GetItem(long(i))->Value;  
  12. 12              if(i==0)  
  13. 13              m_list2.InsertItem(rows,str);                   //查询结果插入到列表  
  14. 14              else  
  15. 15              m_list2.SetItemText(rows,i,str);                //查询结果插入到列表  
  16. 16          }  
  17. 17          UpdateData(false);  
  18. 18      }  
  19. 19      catch(...)  
  20. 20      {  
  21. 21          return;  
  22. 22      }  
  23. 23  } 

第4行代码实现了列表控件中数据的清除功能。

第8~16行代码实现了把查询结果插入到列表。

第19~22行代码实现了执行错误的捕捉。

数据库应用程序中用列表控件输出数据比较方便,上面介绍了列表控件和数据表数据关联的使用过程,读者一定要掌握该控件的使用方法。