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://hi.baidu.com/mgqw864/item/e54b48552b8a56978d12ed7f()
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
- void COCIExampleDlg::OnButtonConnect()
- {
- this->UpdateData (); //更新数据
- //代码5.2,处理SQL的第一步,准备SQL
- wsprintf((char*)textSQL, "SELECT * FROM Score %s",SQL);
- if(status=OCIStmtPrepare(stmthp, errhp,textSQL, strlen((char*)textSQL),OCI_NTV_SYNTAX, OCI_DEFAULT))
- {
- ErrorProc (errhp, status) ;
- return;
- }
- //代码5.3,处理SOL的第三步,执行
- if (status=OCIStmtExecute(svchp, stmthp,errhp, (ub4)0, 0, NULL, NULL, OCI_DEFAULT))
- {
- ErrorProc (errhp, status) ;
- return;
- }
- //代码5.4,处理SOL的第四步,描述
- //代码5.4.1,读取选择列表中的项数
- ErrorProc(errhp, OCIAttrGet(stmthp,OCI_HTYPE_STMT,&col_num, 0, OCI_ATTR_PARAM_COUNT,errhp ));
- int ColumnNumbers=(int) col_num;
- text *namep; //字段名称
- ub4 sizep; //字段名称的字符串长度
- text tempText[100];
- //获取表的字段的属性信息
- int nindex=m_CombolFieldName.GetCurSel();
- if(nindex<0) nindex=0;
- m_CombolFieldName.ResetContent();
- for(int i=0;i<(int)col_num; i++)
- {
- //为选择项分配参数描述符
- ErrorProc(errhp, OCIParamGet(stmthp,OCI_HTYPE_STMT, errhp, (void**)&colhp, ub4(i+1)));
- //读取选择项的数据长度
- ErrorProc(errhp, OCIAttrGet(colhp, OCI_DTYPE_PARAM,&collen[i], 0, OCI_ATTR_DATA_SIZE, errhp ));
- //读取选择项的数据类型
- ErrorProc(errhp, OCIAttrGet(colhp, OCI_DTYPE_PARAM,&coltype[i],0, OCI_ATTR_DATA_TYPE, errhp));
- //若这个字段为日期型,则把其字符宽度置为50
- if (coltype[i]==SQLT_DATE)collen[i] =50;
- //分配缓冲区
- colbuf[i]=(text*)new text[(int)collen[i]+1];
- //代码5.4.2获取字段名称
- ErrorProc(errhp, OCIAttrGet(colhp, OCI_DTYPE_PARAM,(dvoid*)&namep, (ub4*)&sizep, OCI_ATTR_NAME, errhp ));
- strncpy((char*)tempText, (char*)namep, (size_t)sizep) ;
- tempText [sizep]= '\0';
- m_grid.SetTextMatrix(0,i+1,(const char *)tempText); //将数据写入表格控件
- m_CombolFieldName.AddString((const char *)tempText); //将字段名称添加入下拉列表框
- }
- m_CombolFieldName.SetCurSel (nindex);
- //代码5.5,处理SQL的第五步,定义变量
- for(i=0; i<(int)col_num; i++)
- {
- if (status=OCIDefineByPos (stmthp,&defhp[i],errhp, i+1,(ub1*)colbuf[i],
- collen[i]+1,SQLT_STR,&ind[i], 0, 0, OCI_DEFAULT))
- {
- ErrorProc(errhp, status);
- return;
- }
- }
- //代码5.6,处理SQL的第六步,取值
- int row=0;
- CString tempstr;
- while((OCIStmtFetch(stmthp, errhp,1,OCI_FETCH_NEXT,OCI_DEFAULT))!=OCI_NO_DATA)
- {
- row = row+1;
- m_grid.SetRows(row+1); //根据数据的行数动态设置表格控件的最大行数
- tempstr.Format ("%d",row);
- m_grid.SetTextMatrix(row,0,tempstr); //设置序号
- for(i=0; i<(int)col_num; i++)
- {
- tempstr=(char*)colbuf[i];
- tempstr.TrimRight(' '); //删除右空格
- //把获取的用户的基表的数据赋予字段数值数组
- m_grid.SetTextMatrix(row,i+1,tempstr);
- }
- }
- SQL="";
- }
root