SqlDataRecord 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示单个数据行及其元数据。
public ref class SqlDataRecord : System::Data::IDataRecord
public class SqlDataRecord : System.Data.IDataRecord
type SqlDataRecord = class
interface IDataRecord
Public Class SqlDataRecord
Implements IDataRecord
- 继承
-
SqlDataRecord
- 实现
示例
以下示例演示如何创建描述记录的列元数据的多个 SqlMetaData 对象,然后创建可 SqlDataRecord 重用的实例。 设置列SqlDataRecord值,SqlDataRecord可用于将多行流式传输到SQL Server作为表值参数。
using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.SqlClient.Server;
// Stream rows to SQL Server as a table-valued parameter.
public static IEnumerable<SqlDataRecord> CreateNewRecord()
{
// Re-use a single SqlDataRecord instance rather than allocating a new one for each row.
// Each row's values are read before SqlCommand advances to the next one.
SqlDataRecord record;
// Create a new record with the column metadata. The constructor is
// able to accept a variable number of parameters.
record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Column1", SqlDbType.NVarChar, 12),
new SqlMetaData("Column2", SqlDbType.Int),
new SqlMetaData("Column3", SqlDbType.DateTime) });
// Set the record fields.
record.SetString(0, "Hello World!");
record.SetInt32(1, 42);
record.SetDateTime(2, DateTime.Now);
// Stream the first record to SQL Server.
yield return record;
// Set the fields of the second record and stream it to SQL Server.
record.SetInt32(1, 0);
yield return record;
}
注解
此类描述表值参数的单个行。 从描述记录的列元数据的对象数组SqlMetaData中构造一个,使用 Set<Type> 方法填充记录的列元数据,将其包含在一个IEnumerable<SqlDataRecord>并分配给该IEnumerable<SqlDataRecord>Value对象中。
为了在发送多行时获得最佳性能,请跨IEnumerable<SqlDataRecord>迭代器重复使用单个SqlDataRecord实例:为每个行设置新列值和yield return同一实例。
SqlCommand 将在前进到下一个记录之前读取每个记录。
构造函数
| 名称 | 说明 |
|---|---|
| SqlDataRecord(SqlMetaData[]) |
根据作为参数传递的对象SqlMetaData数组,使用架构初始化新SqlDataRecord实例。 |
属性
| 名称 | 说明 |
|---|---|
| FieldCount |
获取数据行中的列数。 此属性为只读。 |
| Item[Int32] |
获取列参数指定的 |
| Item[String] |
获取列参数指定的 |
方法
显式接口实现
| 名称 | 说明 |
|---|---|
| IDataRecord.GetData(Int32) |
此版本不支持。 |