Hi, try this:
CString BuildSQL( const CString& sStringFromFile )
{
CString sSQL, sTemp1, sTemp2;
sSQL = \_T("CREATE TABLE ");
// string at position 0 is the table name
if( AfxExtractSubString( sTemp1, sStringFromFile, 0, ',' ) )
{
sSQL += sTemp1;
sSQL += "( ";
// now add the column names and the column types
for( int i = 1; ; i +=2 )
{
if( AfxExtractSubString( sTemp1, sStringFromFile, i, ',' ) &&
AfxExtractSubString( sTemp2, sStringFromFile, i + 1, ',' ) )
{
sSQL += sTemp1;
sSQL += sTemp2;
sSQL += \_T(", ");
}
else
{
break;
}
}
// remove the last ", "
sSQL.ReleaseBuffer( sSQL.GetLength() - 2 );
sSQL += \_T(" )");
}
return sSQL;
}
Regards Holger Persch