如题
即: /// <summary>
/// 根据给定的数据源pRS,在指定的数据库pDB中创建以strTableName为名的表,
/// 此表应包含源表的所有数据
/// </summary>
/// <param name="pRS">数据源</param>
/// <param name="strTableName">新表表名</param>
/// <param name="pDB">指定的数据库</param>
/// <returns>受影响的记录数</returns>
int CreateTable(CRecordset* pRS,CString strTableName, CDatabase* pDB)
{
}小弟捉摸了几天了,毫无进展如:(
我的办法是通过pRS获得 CODBCFieldInfo ,然后根据 CODBCFieldInfo 获得列信息,先创建空表,然后导数据。
但是我不会通过CODBCFieldInfo获得列的数据类型:(pDB的数据库类型有大家自定,但是希望能注释清楚。谢谢哪位大哥能够帮忙实现,不胜感激!!

解决方案 »

  1.   

    CDatabase::ExecuteSQL
    void ExecuteSQL( LPCSTR lpszSQL );
    throw( CDBException );ParameterslpszSQLPointer to a null-terminated string containing a valid SQL command to execute. You can pass a CString.ResCall this member function when you need to execute an SQL command directly. Create the command as a null-terminated string. ExecuteSQL does not return data records. If you want to operate on records, use a recordset object instead.Most of your commands for a data source are issued through recordset objects, which support commands for selecting data, inserting new records, deleting records, and editing records. However, not all ODBC functionality is directly supported by the database classes, so you may at times need to make a direct SQL call with ExecuteSQL.ExampleCString strCmd = "UPDATE Taxes SET Federal = 36%";TRY
    {
       m_dbCust.ExecuteSQL( strCmd );
    }CATCH(CDBException, e)
    {
       // The error code is in e->m_nRetCode
    }END_CATCHCDatabase Overview |  Class Members |  Hierarchy ChartSee Also   CDatabase::SetLoginTimeout, CRecordset
      

  2.   

    use ur sql string to create a table
      

  3.   

    先生成一个CDatabase类的对象,
    然后直接用SQL语句生成表
    再Executesql()即可啊
      

  4.   

    long l1;
    CString sfieldname
    CODBCFieldInfo fi;
    for (short i =0;i<pRS.GetODBCFieldCount();i++){
    pRS.GetODBCFieldInfo( i, fi );
    l1=fi.m_nPrecision;
    sfieldname=fi.m_strName ;
    ...........
    }struct CODBCFieldInfo
    {
       CString m_strName;
       SWORD m_nSQLType;
       UDWORD m_nPrecision;
       SWORD m_nScale;
       SWORD m_nNullability;
    };
    Parameters
    m_strName 
    The name of the field. 
    m_nSQLType 
    The SQL data type of the field. This can be an ODBC SQL data type or a driver-specific SQL data type. For a list of valid ODBC SQL data types, see "SQL Data Types" in the Platform SDK. For information about driver-specific SQL data types, see the driver's documentation. 
    m_nPrecision 
    The maximum precision of the field. For details, see "Precision, Scale, Length, and Display Size" in the Platform SDK. 
    m_nScale 
    The scale of the field. For details, see "Precision, Scale, Length, and Display Size" in the Platform SDK. 
    m_nNullability 
    Whether the field accepts a Null value. This can be one of two values: SQL_NULLABLE if the field accepts Null values, or SQL_NO_NULLS if the field does not accept Null values. 
      

  5.   

    to楼上诸位:
    /******************
    我的办法是通过pRS获得 CODBCFieldInfo ,然后根据 CODBCFieldInfo 获得列信息,先创建空表,然后导数据。
    但是我不会通过CODBCFieldInfo获得列的数据类型:(
    ******************************/他的问题是不知道如何获得数据类型,比如说 "int"  "char(10)" 之类的字符串啊我的意见是 可否在数据库中启动一个事务,来进行表的拷贝呢?