用于读取数据。
SqlDataReader 对象 | 专用于读取 SQL SERVER 数据 |
OleDbDataReader 对象 | 专用于读取 OLEDB 数据 |
属性 | 描述 |
---|---|
FieldCount | 字段数量 |
IsClosed | 是否已经关闭 |
Item(name|index) | 字段内容 |
RecordsAffected | 操作后受影响的记录数 |
方法 | 描述 |
---|---|
Close() | 关闭 |
GetBoolean(index) | 返回某列的值,Boolean 类型 |
GetByte(index) | 返回某列的值,Byte 类型 |
GetChar(index) | 返回某列的值,Char 类型 |
GetDateTime(index) | 返回某列的值,DateTime 类型 |
GetDecimal(index) | 返回某列的值,Decimal 类型 |
GetDouble(index) | 返回某列的值,Double 类型 |
GetFloat(index) | 返回某列的值,Float 类型 |
GetGuide(index) | 返回某列的值,Guide 类型 |
GetInt16(index) | 返回某列的值,Int16 类型 |
GetInt32(index) | 返回某列的值,Int32 类型 |
GetInt64(index) | 返回某列的值,Int64 类型 |
GetString(index) | 返回某列的值,String 类型 |
GetTimeSpan(index) | 返回某列的值,TimeSpan 类型 |
GetDataTypeName(index) | 获取数据类型名称 |
GetFieldType(index) | 返回某列的数据类型 |
GetName(index) | 返回某列的字段名 |
GetOrdinal(name) | 返回字段序号,从 0 起 |
GetValue(index) | 返回某列的值 |
GetValues(values) | 获取所有字段的值,存入数组 |
IsDBNull(index) | 记录值是否为空 |
Read() | 转到下条记录,返回是否成功,读取第一条记录也需要调用 |
SqlDataReader datareader;
datareader = command.ExecuteReader(); // 循环每条记录 while(datareader.Read()) { // 将字段值加入到下拉列表清单 DropDownList1.Items.Add(datareader.GetValue(0).ToString()); } // 关闭对象 datareader.Close(); |