Freigeben über


Type-Eigenschaft (Beispiel) (VJ++)

Gilt für: Access 2013 | Access 2016

Dieses Beispiel veranschaulicht die Type-Eigenschaft. Es handelt sich um ein Modell eines Hilfsprogramms zum Auflisten der Namen und Typen einer Sammlung, z. B. Eigenschaften, Felder usw.

Wir müssen das Recordset nicht öffnen, um auf seine Properties-Auflistung zuzugreifen. sie entstehen, wenn das Recordset-Objekt instanziiert wird.

Wenn Sie die CursorLocation-Eigenschaft jedoch auf adUseClient festlegen, werden der Properties-Auflistung des Recordset-Objekts mehrere dynamische Eigenschaften hinzugefügt, was das Beispiel etwas interessanter macht. Zur Veranschaulichung verwenden wir explizit die Item-Eigenschaft , um auf jedes Property-Objekt zuzugreifen.

// BegintTypePropertyJ 
import com.ms.wfc.data.*; 
import java.io.* ; 
 
public class TypePropertyX 
{ 
 // The main entry point for the application. 
 
 public static void main (String[] args) 
 { 
 TypePropertyX(); 
 System.exit(0); 
 } 
 
 // TypePropertyX function 
 static void TypePropertyX() 
 { 
 // Define ADO Objects. 
 Recordset rst = null; 
 AdoProperty prop = null; 
 
 // Declarations. 
 BufferedReader in = 
 new BufferedReader (new InputStreamReader(System.in)); 
 String strCnn = "DSN='Pubs';Provider='MSDASQL';Integrated Security='SSPI';"; 
 String strMsg; 
 int intIndex; 
 int intDisplaysize = 15; 
 
 try 
 { 
 rst = new Recordset(); 
 rst.setCursorLocation(AdoEnums.CursorLocation.CLIENT); 
 for(intIndex = 0; 
 intIndex <= rst.getProperties().getCount() - 1;intIndex++) 
 { 
 prop = rst.getProperties().getItem(intIndex); 
 switch(prop.getType()) 
 { 
 case AdoEnums.DataType.BIGINT : 
 strMsg = "adBigInt"; 
 break; 
 case AdoEnums.DataType.BINARY : 
 strMsg = "adBinary"; 
 break; 
 case AdoEnums.DataType.BOOLEAN : 
 strMsg = "adBoolean"; 
 break; 
 case AdoEnums.DataType.BSTR : 
 strMsg = "adBSTR"; 
 break; 
 case AdoEnums.DataType.CHAPTER : 
 strMsg = "adChapter"; 
 break; 
 case AdoEnums.DataType.CHAR : 
 strMsg = "adChar"; 
 break; 
 case AdoEnums.DataType.CURRENCY : 
 strMsg = "adCurrency"; 
 break; 
 case AdoEnums.DataType.DATE : 
 strMsg = "adDate"; 
 break; 
 case AdoEnums.DataType.DBDATE : 
 strMsg = "adDBDate"; 
 break; 
 case AdoEnums.DataType.DBTIME : 
 strMsg = "adDBTime"; 
 break; 
 case AdoEnums.DataType.DBTIMESTAMP : 
 strMsg = "adDBTimeStamp"; 
 break; 
 case AdoEnums.DataType.DECIMAL : 
 strMsg = "adDecimal"; 
 break; 
 case AdoEnums.DataType.DOUBLE : 
 strMsg = "adDouble"; 
 break; 
 case AdoEnums.DataType.EMPTY : 
 strMsg = "adEmpty"; 
 break; 
 case AdoEnums.DataType.ERROR : 
 strMsg = "adError"; 
 break; 
 case AdoEnums.DataType.FILETIME : 
 strMsg = "adFileTime"; 
 break; 
 case AdoEnums.DataType.GUID : 
 strMsg = "adGUID"; 
 break; 
 case AdoEnums.DataType.IDISPATCH : 
 strMsg = "adIDispatch"; 
 break; 
 case AdoEnums.DataType.INTEGER : 
 strMsg = "adInteger"; 
 break; 
 case AdoEnums.DataType.IUNKNOWN : 
 strMsg = "adIUnknown"; 
 break; 
 case AdoEnums.DataType.LONGVARBINARY : 
 strMsg = "adLongVarBinary"; 
 break; 
 case AdoEnums.DataType.LONGVARCHAR : 
 strMsg = "adLongVarChar"; 
 break; 
 case AdoEnums.DataType.LONGVARWCHAR : 
 strMsg = "adLongVarWChar"; 
 break; 
 case AdoEnums.DataType.NUMERIC : 
 strMsg = "adNumeric"; 
 break; 
 case AdoEnums.DataType.PROPVARIANT : 
 strMsg = "adPropVariant"; 
 break; 
 case AdoEnums.DataType.SINGLE : 
 strMsg = "adSingle"; 
 break; 
 case AdoEnums.DataType.SMALLINT : 
 strMsg = "adSmallInt"; 
 break; 
 case AdoEnums.DataType.TINYINT : 
 strMsg = "adTinyInt"; 
 break; 
 case AdoEnums.DataType.UNSIGNEDBIGINT : 
 strMsg = "adUnsignedBigInt"; 
 break; 
 case AdoEnums.DataType.UNSIGNEDINT : 
 strMsg = "adUnsignedInt"; 
 break; 
 case AdoEnums.DataType.UNSIGNEDSMALLINT : 
 strMsg = "adUnsignedSmallInt"; 
 break; 
 case AdoEnums.DataType.UNSIGNEDTINYINT : 
 strMsg = "adUnsignedTinyInt"; 
 break; 
 case AdoEnums.DataType.USERDEFINED : 
 strMsg = "adUserDefined"; 
 break; 
 case AdoEnums.DataType.VARBINARY : 
 strMsg = "adVarBinary"; 
 break; 
 case AdoEnums.DataType.VARCHAR : 
 strMsg = "adVarChar"; 
 break; 
 case AdoEnums.DataType.VARIANT : 
 strMsg = "adVariant"; 
 break; 
 case AdoEnums.DataType.VARNUMERIC : 
 strMsg = "adVarNumeric"; 
 break; 
 case AdoEnums.DataType.VARWCHAR : 
 strMsg = "adVarWChar"; 
 break; 
 case AdoEnums.DataType.WCHAR : 
 strMsg = "adWChar"; 
 break; 
 default: 
 strMsg = "*UNKNOWN*"; 
 break; 
 } 
 System.out.println("Property " + 
 Integer.toString(intIndex) + 
 " : " + 
 prop.getName() + 
 ", Type = " + 
 strMsg); 
 if(intIndex % intDisplaysize == 0 && intIndex != 0) 
 { 
 System.out.println("\nPress <Enter> to continue.."); 
 in.readLine(); 
 } 
 } 
 
 System.out.println("\nPress <Enter> to continue.."); 
 in.readLine(); 
 } 
 catch( AdoException ae ) 
 { 
 // Notify user of any errors that result from ADO. 
 
 // As passing a Recordset, check for null pointer first. 
 if (rst != null) 
 { 
 PrintProviderError(rst.getActiveConnection()); 
 } 
 else 
 { 
 System.out.println("Exception: " + ae.getMessage()); 
 } 
 } 
 
 // System read requires this catch. 
 catch( java.io.IOException je) 
 { 
 PrintIOError(je); 
 } 
 
 finally 
 { 
 // Cleanup objects before exit. 
 if (rst != null) 
 if (rst.getState() == 1) 
 rst.close(); 
 } 
 } 
 
 // PrintProviderError Function 
 static void PrintProviderError(Connection cnn1) 
 { 
 // Print Provider Errors from Connection Object. 
 // ErrItem is an item object in the Connections Errors Collection. 
 com.ms.wfc.data.Error ErrItem = null; 
 long nCount = 0; 
 int i = 0; 
 
 nCount = cnn1.getErrors().getCount(); 
 
 // If there are any errors in the collection, print them. 
 if ( nCount > 0) 
 { 
 // Collection ranges from 0 to nCount-1. 
 for ( i=0;i<nCount; i++) 
 { 
 ErrItem = cnn1.getErrors().getItem(i); 
 System.out.println("\t Error Number: " + ErrItem.getNumber() 
 + "\t" + ErrItem.getDescription()); 
 } 
 } 
 } 
 // PrintIOError Function 
 static void PrintIOError(java.io.IOException je) 
 { 
 System.out.println("Error: \n"); 
 System.out.println("\t Source: " + je.getClass() + "\n"); 
 System.out.println("\t Description: "+ je.getMessage() + "\n"); 
 } 
} 
// EndTypePropertyJ 

Siehe auch

Support und Feedback

Haben Sie Fragen oder Feedback zu Office VBA oder zu dieser Dokumentation? Unter Office VBA-Support und Feedback finden Sie Hilfestellung zu den Möglichkeiten, wie Sie Support erhalten und Feedback abgeben können.