当前位置: 首页>>代码示例>>C++>>正文


C++ CRecordset::GetODBCFieldInfo方法代码示例

本文整理汇总了C++中CRecordset::GetODBCFieldInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ CRecordset::GetODBCFieldInfo方法的具体用法?C++ CRecordset::GetODBCFieldInfo怎么用?C++ CRecordset::GetODBCFieldInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRecordset的用法示例。


在下文中一共展示了CRecordset::GetODBCFieldInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetFieldList

BOOL CBCGPODBCGridCtrl::GetFieldList (LPCTSTR lpszTable, CStringList& lstField)
{
	ASSERT (lpszTable != NULL);

	lstField.RemoveAll ();

	if (m_pDataBase == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	try
	{
		ASSERT_VALID (m_pDataBase);

		if (!m_pDataBase->IsOpen ())
		{
			ASSERT (FALSE);
			return FALSE;
		}

		CRecordset* pRecordSet = new CRecordset (m_pDataBase);

		CString strSQL = _T("SELECT * FROM ");
		strSQL += lpszTable;

		if (!pRecordSet->Open (CRecordset::forwardOnly, strSQL))
		{
			delete pRecordSet;
			return FALSE;
		}

		const short nColumns = pRecordSet->GetODBCFieldCount ();

		for (short nColumn = 0; nColumn < nColumns; nColumn++)
		{
			CODBCFieldInfo fieldinfo;
			pRecordSet->GetODBCFieldInfo (nColumn, fieldinfo);

			lstField.AddTail (fieldinfo.m_strName);
		}

		pRecordSet->Close ();
		delete pRecordSet;
	}
	catch (CDBException* pEx)
	{
		OnODBCException (pEx);
		pEx->Delete ();

		return FALSE;
	}

	return TRUE;
}
开发者ID:iclosure,项目名称:jframework,代码行数:56,代码来源:BCGPODBCGridCtrl.cpp

示例2: OnInitDialog

BOOL CFieldContentsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	try
	{		
	//	prüfe Parameter
		ASSERT (NULL != m_pDatabase && m_pDatabase -> IsOpen ());
		ASSERT (!m_strField.IsEmpty ());
		ASSERT (!m_strTable.IsEmpty ());

	//	Listbox füllen
		CWaitCursor wc;

	//	zuerst SelectString zusammenbauen
		CString strSelect;
		AfxFormatString2 (strSelect, IDS_SELECT_FIELD, m_strField, m_strTable);
		CRecordset rs (m_pDatabase);
		VERIFY (rs.Open (CRecordset::forwardOnly, strSelect, CRecordset::readOnly));
		CString strVal;
		int iMax = 0;
		while (!rs.IsEOF ())
		{
			rs.GetFieldValue (m_strField, strVal);
			if (!strVal.IsEmpty ())
			{
				if (m_lbFields.AddString (strVal) < 0)
					AfxThrowMemoryException ();
				iMax = max (iMax, strVal.GetLength ());
			}
			rs.MoveNext ();
		}

	//	HorizontalExtent setzen
		if (iMax > 0)
		{
			WORD wUnits = LOWORD (:: GetDialogBaseUnits ());
			m_lbFields.SetHorizontalExtent (wUnits * iMax);
		}

	//	TypInfo ausgeben
		CODBCFieldInfo FieldInfo;
		rs.GetODBCFieldInfo (m_strField, FieldInfo);
		switch (FieldInfo.m_nSQLType)
		{
			case SQL_DATE:		//	Zeitformate
			case SQL_TIME:
			case SQL_TIMESTAMP:		
			{
				m_uiResID = IDS_DATETIME_FORMAT;
				VERIFY (m_strFieldType.LoadString (IDS_DATE_TIME));
			}
			break;
			case SQL_DECIMAL:   
			case SQL_NUMERIC:   
			case SQL_BIGINT: 
			case SQL_CHAR:
			case SQL_VARCHAR:
			{
				m_uiResID = IDS_STRING_FORMAT;
				VERIFY (m_strFieldType.LoadString (IDS_TEXT));
			}
			break;
			default:			//	 alle Zahlenformate
				VERIFY (m_strFieldType.LoadString (IDS_ZAHL));
			break;
		}
	
	//	Caption setzen
		CString strFormat;
		GetWindowText (strFormat);
		strVal.Format (strFormat, m_strTable);
		SetWindowText (strVal);

	//	Feldname setzen
		m_strFieldName = FieldInfo.m_strName;

	//	Controls setzen
		m_lbFields.EnableWindow (m_lbFields.GetCount () > 0);	
		m_btOk.EnableWindow (FALSE);

		rs.Close ();

		UpdateData (FALSE);
	}
	catch (CException *e)
	{
		e -> ReportError ();
		e -> Delete ();
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
开发者ID:hkaiser,项目名称:TRiAS,代码行数:94,代码来源:FCONTDLG.CPP

示例3: GetStaticData

void CEdRptDoc::GetStaticData(CRecordset &rc)
{
	if (!rc.IsOpen())
		return;

	CString csTmp;

	GV_ITEM Item;
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX;	
	Item.row = m_Grid.GetRowCount() - 1;	
	Item.col = 0;
	Item.szText = "总计";
	m_Grid.SetItem(&Item);

	CString csFormat;
	CODBCFieldInfo fi;
	for (Item.col = 1; Item.col < m_ColFmt.GetSize(); Item.col++)
	{
		if (m_ColFmt[Item.col].format.IsEmpty())
		{
			rc.GetODBCFieldInfo(short(Item.col), fi);
			if (fi.m_nSQLType == SQL_NUMERIC || fi.m_nSQLType == SQL_DECIMAL)
			{
				if (fi.m_nScale == 0)
				{
					fi.m_nSQLType = SQL_INTEGER;
					csFormat.Format("%%%dd", fi.m_nPrecision);				
				}
				else
				{
					fi.m_nSQLType = SQL_FLOAT;
					csFormat.Format("%%%d.%df", fi.m_nPrecision, fi.m_nScale);				
				}
			}
		}
		else
		{
			csFormat = m_ColFmt[Item.col].format;
			if (csFormat.FindOneOf("dioux") > 0)
				fi.m_nSQLType = SQL_INTEGER;
			else if (csFormat.FindOneOf("eEfgG") > 0)
				fi.m_nSQLType = SQL_FLOAT;
			else
				fi.m_nSQLType = SQL_DATETIME;
		}

		switch(fi.m_nSQLType)
		{
		case SQL_INTEGER:
		case SQL_SMALLINT:
		case SQL_TINYINT:
		case SQL_BIGINT:
			fi.m_nSQLType = SQL_INTEGER;
			if (csFormat.IsEmpty())
				csFormat = _T("%d");
			break;

		case SQL_FLOAT:
		case SQL_REAL:
		case SQL_DOUBLE:
			fi.m_nSQLType = SQL_FLOAT;
			if (csFormat.IsEmpty())
				csFormat = _T("%f");
			break;
		default:
			break;
		}
		
		double fSum = 0.0;
		if (fi.m_nSQLType == SQL_INTEGER || fi.m_nSQLType == SQL_FLOAT)
		{
			CString csTmp;
			for (int j = 1; j < m_Grid.GetRowCount() - 1; j++)
			{
				csTmp = m_Grid.GetItemText(j, Item.col);
				fSum += atof(csTmp);
			}
		}
		
		if (fi.m_nSQLType == SQL_INTEGER)
			Item.szText.Format(csFormat, (int)fSum);
		else if (fi.m_nSQLType == SQL_FLOAT)
			Item.szText.Format(csFormat, fSum);
		else
			Item.szText = "--:--";

		Item.szText.TrimLeft();
		Item.szText.TrimRight();
		m_Grid.SetItem(&Item);	
	}
	
}
开发者ID:zphseu,项目名称:cuiyan,代码行数:93,代码来源:EdRptDoc.cpp


注:本文中的CRecordset::GetODBCFieldInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。