// Make sure SQLTables exists
AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
SQL_API_SQLTABLES,&bFunctionExists));
if (!Check(nRetCode) || !bFunctionExists)
{
if (!bFunctionExists)
TRACE(_T("SQLTables not supported\n"));
return FALSE;
}
// Cache state info and allocate hstmt
SetState(nOpenType,NULL,readOnly);
if (!AllocHstmt())
return FALSE;
TRY
{
OnSetOptions(m_hstmt);
AllocStatusArrays();
// Call the ODBC function
AFX_ODBC_CALL(::SQLTables(m_hstmt,
(UCHAR FAR*)pszTableQualifier,SQL_NTS,
(UCHAR FAR*)pszTableOwner,SQL_NTS,
(UCHAR FAR*)pszTableName,SQL_NTS,
(UCHAR FAR*)pszTableType,SQL_NTS));
if (!Check(nRetCode))
ThrowDBException(nRetCode,m_hstmt);
// Allocate memory and cache info
AllocAndCacheFieldInfo();
AllocRowset();
// Fetch the first row of data
MoveNext();
// If EOF, result set is empty, set BOF as well
m_bBOF = m_bEOF;
char lpszType[64];
strcpy(lpszType, "'TABLE'");
tb.Open(NULL,NULL,NULL,lpszType,CRecordset::snapshot);
while (! tb.IsEOF()){
ml.AddString(tb.m_strTableName);
tb.MoveNext();
}
//m1.SetWindowText(s1);
tb.Close();
db.Close();
第二个问题:
如果课程数是确定的话可以一条sql语句搞定。然后用:db.ExecuteSQL(..)来执行。
sql语句是:
insert into tbalename select 学号,姓名,年龄,(select 成绩 from 成绩表 where 学号=学生表.学号 and 课程号=1 ),(select 成绩 from 成绩表 where 学号=学生表.学号 and 课程号=2 ),(select 成绩 from 成绩表 where 学号=学生表.学号 and 课程号=3 ) from 学生表