SqlDataReader.FieldCount 屬性

定義

取得目前資料列中的資料行數目。Gets the number of columns in the current row.

public:
 property int FieldCount { int get(); };
public int FieldCount { get; }
member this.FieldCount : int
Public ReadOnly Property FieldCount As Integer

屬性值

當未置於有效資料錄集 (Recordset) 時,則為 0,否則為目前資料列中的資料行數目。When not positioned in a valid recordset, 0; otherwise the number of columns in the current row. 預設值為 -1。The default is -1.

實作

例外狀況

目前沒有連接至 SQL Server 的執行個體。There is no current connection to an instance of SQL Server.

備註

依本質執行查詢時,不會傳回資料列(例如刪除查詢),會將 FieldCount 設定為0。Executing a query that, by its nature, does not return rows (such as a DELETE query), sets FieldCount to 0. 不過.However. 這不應該與傳回0個數據列的查詢混淆(例如 SELECT * FROM table WHERE 1 = 2),此時 FieldCount 會傳回資料表中的資料行數目,包括隱藏的欄位。this should not be confused with a query that returns 0 rows (such as SELECT * FROM table WHERE 1 = 2) in which case FieldCount returns the number of columns in the table, including hidden fields. 使用 VisibleFieldCount 以排除隱藏欄位。Use VisibleFieldCount to exclude hidden fields.

適用於

另請參閱