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。
為了在傳送多列時最佳效能,建議在迭代器中重複使用單一 SqlDataRecord 實例 IEnumerable<SqlDataRecord> :設定新的欄位值,並為 yield return 每列設定相同的實例。
SqlCommand 我會先閱讀每條紀錄,然後再進入下一筆。
建構函式
| 名稱 | Description |
|---|---|
| SqlDataRecord(SqlMetaData[]) |
根據作為參數傳遞的SqlMetaData物件陣列,初始化一個新的SqlDataRecord實例。 |
屬性
| 名稱 | Description |
|---|---|
| FieldCount |
取得資料列的欄位數量。 這個屬性是唯讀的。 |
| Item[Int32] |
取得由欄位 |
| Item[String] |
取得由欄位 |
方法
明確介面實作
| 名稱 | Description |
|---|---|
| IDataRecord.GetData(Int32) |
本版本不支援。 |