Udostępnij za pośrednictwem


db_table

Opens an OLE DB table.

[ db_table( 
   db_table, 
   name, 
   source_name, 
   hresult 
) ]

Parameters

  • db_table
    A string specifying the name of a database table (such as "Products").

  • name (optional)
    The name of the handle you use to work with the table. You must specify this parameter if you want to return more than one row of results. db_table generates a variable with the specified name that can be used to traverse the rowset or execute multiple action queries.

  • source_name (optional)
    The CSession variable or instance of a class that has the db_source attribute applied to it on which the command executes. See db_source.

  • hresult (optional)
    Identifies the variable that will receive the HRESULT of this database command. If the variable does not exist, it will be automatically injected by the attribute.

Remarks

db_table creates a CTable object, which is used by an OLE DB consumer to open a table. You can use this attribute only at the class level; you cannot use it inline. Use db_column to bind table columns to variables; use db_param to delimit (set the parameter type and so on) of parameters.

When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to _YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see both classes.

Example

The following example opens the Products table for use by CProducts.

// db_table.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>

[ db_table(L"dbo.Products") ]
class CProducts {
   [ db_column("1") ] LONG m_ProductID;
};

Requirements

Attribute Context

Applies to

class, struct

Repeatable

No

Required attributes

None

Invalid attributes

None

For more information about the attribute contexts, see Attribute Contexts.

See Also

Concepts

Visual C++ Samples

Other Resources

OLE DB Consumer Attributes