DataTableReader.GetDouble(Int32) 方法
定义
获取双精度浮点数形式的列值。Gets the value of the column as a double-precision floating point number.
public:
override double GetDouble(int ordinal);
public override double GetDouble (int ordinal);
override this.GetDouble : int -> double
Public Overrides Function GetDouble (ordinal As Integer) As Double
参数
- ordinal
- Int32
从零开始的列序号。The zero-based ordinal of the column.
返回
指定列的值。The value of the specified column.
例外
传递的索引超出了 0 到 FieldCount -1 的范围。The index passed was outside the range of 0 to FieldCount - 1.
尝试从已删除的行中检索数据。An attempt was made to retrieve data from a deleted row.
尝试读取或访问已关闭的 DataTableReader 中的列。An attempt was made to read or access a column in a closed DataTableReader.
指定的列不包含双精度浮点数。The specified column does not contain a double-precision floating point number.
示例
下面的示例在传入的中显示编号为2的列的内容 DataTableReader 。The following example displays the contents of the column numbered 2 within the passed-in DataTableReader. 如果特定行中的列的值为 null,则代码将显示文本 <NULL> 。If the value the column within a particular row is null, the code displays the text <NULL>. 如果列中的数据类型不正确,则此示例将为每一行显示一条错误消息。If the data within the column is not of the correct type, the example displays an error message for each row.
private static void PrintColumn(DataTableReader reader)
{
// Loop through all the rows in the DataTableReader
while (reader.Read())
{
if (reader.IsDBNull(2))
{
Console.Write("<NULL>");
}
else
{
try
{
Console.Write(reader.GetBoolean(2));
}
catch (InvalidCastException)
{
Console.Write("Invalid data type.");
}
}
Console.WriteLine();
}
}
Private Sub PrintColumn(ByVal reader As DataTableReader)
' Loop through all the rows in the DataTableReader
While reader.Read()
If reader.IsDBNull(2) Then
Console.Write("<NULL>")
Else
Try
Console.Write(reader.GetBoolean(2))
Catch ex As InvalidCastException
Console.Write("Invalid data type.")
End Try
End If
Console.WriteLine()
End While
End Sub
注解
不执行任何转换;因此,检索的数据必须已经是双精度浮点数,或者必须强制为双精度浮点数。No conversions are performed; therefore the data retrieved must already be a double-precision floating point number or must be coercible to a double-precision floating point number.
调用 IsDBNull 此方法之前,请调用以查看是否存在 null 值。Call IsDBNull to see if there are null values before calling this method.