ODBC是不是一定要DoFieldExchange进行数据邦定的?要是程序作好后数据库表的结构变了怎么办?不就要修改整个程序了吗?哪有这么不方便的技术的?
解决方案 »
- WTL
- 讨论下GetQueuedCompletionStatus()第3个参数到底有什么要求
- 如何在定制的CFILEDIALOG的对话框加上图标(在“打开”的左边),谢谢
- 有没有VC的中级水平想换工作的?
- long型变量和CWnd*指针之间强制转换会不会出错。
- 对话框关闭问题
- 初学者的问题,error LNK2001: unresolved external symbol "public:
- 谁知道怎么算这个题目?(多媒体考试)
- 怎么使用VC完成WORD书签的删除工作
- 一个CreateProcess(...)的问题 ,看看有僧麽問題!謝謝
- VC++编译错
- 请问各位大虾,在网络当中如何才能得到本地以及其他的计算机的IP地址和计算机名。(最好有源代码)谢谢!!!!!!
rs.Open(CRecordset::forwardOnly,,"SQL语句");
CString szValues;
rs.GetFieldValue("fieldname", szValues);
或
rs.GetFieldValue(short(0), szValues);
MSDN:
void GetFieldValue(
LPCTSTR lpszName,
CDBVariant& varValue,
short nFieldType = DEFAULT_FIELD_TYPE
);
void GetFieldValue(
short nIndex,
CDBVariant& varValue,
short nFieldType = DEFAULT_FIELD_TYPE
);
void GetFieldValue(
short nIndex,
CStringA& strValue
);
void GetFieldValue(
short nIndex,
CStringW& strValue
);
Parameters
lpszName
The name of a field.
varValue
A reference to a CDBVariant object that will store the field's value.
nFieldType
The ODBC C data type of the field. Using the default value, DEFAULT_FIELD_TYPE, forces GetFieldValue to determine the C data type from the SQL data type, based on the following table. Otherwise, you can specify the data type directly or choose a compatible data type; for example, you can store any data type into SQL_C_CHAR. C data type SQL data type
SQL_C_BIT SQL_BIT
SQL_C_UTINYINT SQL_TINYINT
SQL_C_SSHORT SQL_SMALLINT
SQL_C_SLONG SQL_INTEGER
SQL_C_FLOAT SQL_REAL
SQL_C_DOUBLE SQL_FLOAT
SQL_DOUBLE
SQL_C_TIMESTAMP SQL_DATE
SQL_TIME
SQL_TIMESTAMP
SQL_C_CHAR SQL_NUMERIC
SQL_DECIMAL
SQL_BIGINT
SQL_CHAR
SQL_VARCHAR
SQL_LONGVARCHAR
SQL_C_BINARY SQL_BINARY
SQL_VARBINARY
SQL_LONGVARBINARY For more information about ODBC data types, see the topics "SQL Data Types" and "C Data Types" in Appendix D of the Platform SDK. nIndex
The zero-based index of the field.
strValue
A reference to a CString object that will store the field's value converted to text, regardless of the field's data type.
Res
You can look up a field either by name or by index. You can store the field value in either a CDBVariant object or a CString object.If you have implemented bulk row fetching, the current record is always positioned on the first record in a rowset. To use GetFieldValue on a record within a given rowset, you must first call the SetRowsetCursorPosition member function to move the cursor to the desired row within that rowset. Then call GetFieldValue for that row. To implement bulk row fetching, you must specify the CRecordset::useMultiRowFetch option of the dwOptions parameter in the Open member function.You can use GetFieldValue to dynamically fetch fields at run time rather than statically binding them at design time. For example, if you have declared a recordset object directly from CRecordset, you must use GetFieldValue to retrieve the field data; record field exchange (RFX), or bulk record field exchange (Bulk RFX), is not implemented.Note If you declare a recordset object without deriving from CRecordset, do not have the ODBC Cursor Library loaded. The cursor library requires that the recordset have at least one bound column; however, when you use CRecordset directly, none of the columns are bound. The member functions CDatabase::OpenEx and CDatabase::Open control whether the cursor library will be loaded.
GetFieldValue calls the ODBC API function SQLGetData. If your driver outputs the value SQL_NO_TOTAL for the actual length of the field value, GetFieldValue throws an exception. For more information about SQLGetData, see the Platform SDK.Exceptions
This method can throw exceptions of type CDBException* and CMemoryException*.Example
The following sample code illustrates calls to GetFieldValue for a recordset object declared directly from CRecordset.// Create and open a database object;
// do not load the cursor library
CDatabase db;
db.OpenEx( NULL, CDatabase::forceOdbcDialog );// Create and open a recordset object
// directly from CRecordset. Note that a
// table must exist in a connected database.
// Use forwardOnly type recordset for best
// performance, since only MoveNext is required
CRecordset rs( &db );
rs.Open( CRecordset::forwardOnly,
_T( "SELECT * FROM SomeTable" ) );// Create a CDBVariant object to
// store field data
CDBVariant varValue;// Loop through the recordset,
// using GetFieldValue and
// GetODBCFieldCount to retrieve
// data in all columns
short nFields = rs.GetODBCFieldCount( );
while( !rs.IsEOF( ) )
{
for( short index = 0; index < nFields; index++ )
{
rs.GetFieldValue( index, varValue );
// do something with varValue
}
rs.MoveNext( );
}rs.Close( );
db.Close( );
Note Unlike the DAO class CDaoRecordset, CRecordset does not have a SetFieldValue member function. If you create an object directly from CRecordset, it is effectively read-only.
For more information about bulk row fetching, see the article Recordset: Fetching Records in Bulk (ODBC).See Also
CRecordset Overview | Class Members | Hierarchy Chart | CRecordset::DoFieldExchange | CRecordset::DoBulkFieldExchange | CRecordset::GetODBCFieldCount | CRecordset::GetODBCFieldInfo | CRecordset::SetRowsetCursorPosition--------------------------------------------------------------------------------Send feedback to Microsoft© 2001 Microsoft Corporation. All rights reserved.