FieldCount
Int32 fieldCount = DataReader.FieldCount;
Returns the number of columns in the current row. If you
aren’t currently positioned on a valid row, the
FieldCount
returns 0.
The following code displays the number of rows, which is 2, because the query includes only two columns:
string SQL = "SELECT CustomerID, ContactTitle FROM Customers"; SqlCommand cmd = new SqlCommand(SQL, con); SqlDataReader r; con.Open(); r = cmd.ExecuteReader(); r.Read(); Console.WriteLine(r.FieldCount.ToString() + " rows were returned."); con.Close();