oracle oci 调用 1

http://blog.163.com/earth_of_fire/blog/static/1368943200791211622278/(总结)

http://blog.163.com/earth_of_fire/blog/static/1368943200791223416510/(数据列表)

http://blog.163.com/earth_of_fire/blog/static/13689432007918112936198/(select)

http://www.cnblogs.com/hustskyking/p/webAudio-listen.html

 

http://blog.csdn.net/evgd2288/article/details/6607035 (好)

http://hi.baidu.com/mgqw864/item/e54b48552b8a56978d12ed7f()

http://blog.csdn.net/wbj1234566/article/details/2003200()

http://read.pudn.com/downloads51/sourcecode/windows/database/176187/OCIExample/OCIExampleDlg.cpp__.htm:

http://www.pudn.com/downloads51/sourcecode/windows/database/detail176187.html

http://read.pudn.com/downloads195/sourcecode/database/916923/testoci/testociDlg.cpp__.htm

http://www.pudn.com/downloads195/sourcecode/database/detail916923.html

  1. void COCIExampleDlg::OnButtonConnect()    
  2. {   
  3.        
  4.     this->UpdateData ();   //更新数据   
  5.        
  6.     //代码5.2,处理SQL的第一步,准备SQL   
  7.     wsprintf((char*)textSQL, "SELECT * FROM Score %s",SQL);   
  8.    
  9.     if(status=OCIStmtPrepare(stmthp, errhp,textSQL, strlen((char*)textSQL),OCI_NTV_SYNTAX, OCI_DEFAULT))   
  10.     {   
  11.         ErrorProc (errhp, status) ;    
  12.         return;   
  13.     }   
  14.        
  15.     //代码5.3,处理SOL的第三步,执行   
  16.     if (status=OCIStmtExecute(svchp, stmthp,errhp, (ub4)0, 0, NULL, NULL, OCI_DEFAULT))   
  17.     {   
  18.         ErrorProc (errhp, status) ;    
  19.         return;   
  20.     }   
  21.            
  22.     //代码5.4,处理SOL的第四步,描述       
  23.     //代码5.4.1,读取选择列表中的项数   
  24.     ErrorProc(errhp, OCIAttrGet(stmthp,OCI_HTYPE_STMT,&col_num, 0, OCI_ATTR_PARAM_COUNT,errhp ));   
  25.     int ColumnNumbers=(int) col_num;   
  26.     text    *namep;     //字段名称   
  27.     ub4     sizep;      //字段名称的字符串长度   
  28.     text    tempText[100];   
  29.    
  30.     //获取表的字段的属性信息   
  31.     int nindex=m_CombolFieldName.GetCurSel();   
  32.     if(nindex<0) nindex=0;   
  33.     m_CombolFieldName.ResetContent();   
  34.     for(int i=0;i<(int)col_num; i++)   
  35.     {   
  36.         //为选择项分配参数描述符   
  37.         ErrorProc(errhp, OCIParamGet(stmthp,OCI_HTYPE_STMT, errhp, (void**)&colhp, ub4(i+1)));   
  38.        
  39.         //读取选择项的数据长度   
  40.         ErrorProc(errhp, OCIAttrGet(colhp, OCI_DTYPE_PARAM,&collen[i], 0, OCI_ATTR_DATA_SIZE, errhp ));   
  41.            
  42.         //读取选择项的数据类型   
  43.         ErrorProc(errhp, OCIAttrGet(colhp, OCI_DTYPE_PARAM,&coltype[i],0, OCI_ATTR_DATA_TYPE, errhp));   
  44.        
  45.         //若这个字段为日期型,则把其字符宽度置为50   
  46.         if (coltype[i]==SQLT_DATE)collen[i] =50;   
  47.            
  48.         //分配缓冲区   
  49.         colbuf[i]=(text*)new text[(int)collen[i]+1];   
  50.            
  51.         //代码5.4.2获取字段名称   
  52.         ErrorProc(errhp, OCIAttrGet(colhp, OCI_DTYPE_PARAM,(dvoid*)&namep, (ub4*)&sizep, OCI_ATTR_NAME, errhp ));   
  53.         strncpy((char*)tempText, (char*)namep, (size_t)sizep) ;   
  54.         tempText [sizep]= '\0';   
  55.         m_grid.SetTextMatrix(0,i+1,(const char *)tempText); //将数据写入表格控件   
  56.         m_CombolFieldName.AddString((const char *)tempText); //将字段名称添加入下拉列表框   
  57.     }      
  58.     m_CombolFieldName.SetCurSel (nindex);   
  59.     
  60.     //代码5.5,处理SQL的第五步,定义变量   
  61.     for(i=0; i<(int)col_num; i++)   
  62.     {   
  63.         if (status=OCIDefineByPos (stmthp,&defhp[i],errhp, i+1,(ub1*)colbuf[i],   
  64.             collen[i]+1,SQLT_STR,&ind[i], 0, 0, OCI_DEFAULT))   
  65.         {   
  66.             ErrorProc(errhp, status);    
  67.             return;   
  68.         }   
  69.     }   
  70.    
  71.     //代码5.6,处理SQL的第六步,取值               
  72.     int row=0;   
  73.     CString tempstr;   
  74.     while((OCIStmtFetch(stmthp, errhp,1,OCI_FETCH_NEXT,OCI_DEFAULT))!=OCI_NO_DATA)   
  75.     {   
  76.         row = row+1;   
  77.         m_grid.SetRows(row+1); //根据数据的行数动态设置表格控件的最大行数   
  78.         tempstr.Format ("%d",row);   
  79.         m_grid.SetTextMatrix(row,0,tempstr); //设置序号   
  80.         for(i=0; i<(int)col_num; i++)   
  81.         {   
  82.             tempstr=(char*)colbuf[i];   
  83.             tempstr.TrimRight(' '); //删除右空格   
  84.             //把获取的用户的基表的数据赋予字段数值数组   
  85.             m_grid.SetTextMatrix(row,i+1,tempstr);   
  86.         }   
  87.            
  88.     }   
  89.            
  90.     SQL="";   
  91.        
  92. }   
posted @ 2014-02-20 20:05  midu  阅读(579)  评论(0编辑  收藏  举报