SqlCommandBuilder.GetInsertCommand 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得自動產生 SqlCommand 的物件,用於對資料庫進行插入。
多載
| 名稱 | Description |
|---|---|
| GetInsertCommand() |
取得自動產生 SqlCommand 的物件,用於對資料庫進行插入。 |
| GetInsertCommand(Boolean) |
取得自動產生 SqlCommand 的物件,用於對資料庫進行插入。 |
備註
應用程式可將此 GetInsertCommand 方法用於資訊或故障排除,因為它會回傳 SqlCommand 待執行的物件。
你也可以用它 GetInsertCommand 作為修改指令的基礎。 例如,你可以呼叫 GetInsertCommand 並修改 該 CommandTimeout 值,然後明確設定在 SqlDataAdapter。
在 Transact-SQL 陳述句首次產生後,應用程式若以任何方式更改該陳述,必須明確呼叫 RefreshSchema。 否則,他們 GetInsertCommand 仍會使用前述陳述的資訊,這可能不正確。 當應用程式呼叫 Update 或 GetInsertCommand 時,Transact-SQL 語句會首先產生。
如需詳細資訊,請參閱使用 CommandBuilder 產生命令。
GetInsertCommand()
取得自動產生 SqlCommand 的物件,用於對資料庫進行插入。
public:
System::Data::SqlClient::SqlCommand ^ GetInsertCommand();
public System.Data.SqlClient.SqlCommand GetInsertCommand();
member this.GetInsertCommand : unit -> System.Data.SqlClient.SqlCommand
override this.GetInsertCommand : unit -> System.Data.SqlClient.SqlCommand
Public Function GetInsertCommand () As SqlCommand
傳回
執行插入所需的自動生成 SqlCommand 物件。
備註
應用程式可將此 GetInsertCommand 方法用於資訊或故障排除,因為它會回傳 SqlCommand 待執行的物件。
你也可以用它 GetInsertCommand 作為修改指令的基礎。 例如,你可以呼叫 GetInsertCommand 並修改 該 CommandTimeout 值,然後明確設定在 SqlDataAdapter。
在 Transact-SQL 陳述句首次產生後,應用程式若以任何方式更改該陳述,必須明確呼叫 RefreshSchema。 否則,他們 GetInsertCommand 仍會使用前述陳述的資訊,這可能不正確。 當應用程式呼叫 Update 或 GetInsertCommand 時,Transact-SQL 語句會首先產生。
如需詳細資訊,請參閱使用 CommandBuilder 產生命令。
另請參閱
適用於
GetInsertCommand(Boolean)
取得自動產生 SqlCommand 的物件,用於對資料庫進行插入。
public:
System::Data::SqlClient::SqlCommand ^ GetInsertCommand(bool useColumnsForParameterNames);
public System.Data.SqlClient.SqlCommand GetInsertCommand(bool useColumnsForParameterNames);
override this.GetInsertCommand : bool -> System.Data.SqlClient.SqlCommand
Public Function GetInsertCommand (useColumnsForParameterNames As Boolean) As SqlCommand
參數
- useColumnsForParameterNames
- Boolean
若 true,則產生與欄位名稱相符的參數名稱(若可能)。 若 false,則生成 @p1, @p2依此類推。
傳回
自動產生 SqlCommand 的物件,用於插入。
備註
應用程式可將此 GetInsertCommand 方法用於資訊或故障排除,因為它會回傳 SqlCommand 待執行的物件。
你也可以用它 GetInsertCommand 作為修改指令的基礎。 例如,你可以呼叫 GetInsertCommand 並修改 該 CommandTimeout 值,然後明確設定在 SqlDataAdapter。
在 Transact-SQL 陳述句首次產生後,應用程式若以任何方式更改該陳述,必須明確呼叫 RefreshSchema。 否則,他們 GetInsertCommand 仍會使用前述陳述的資訊,這可能不正確。 當應用程式呼叫 Update 或 GetInsertCommand 時,Transact-SQL 語句會首先產生。
預設行為在產生參數名稱時,會使用 @p1、 @p2、 等來表示各種參數。 通過 true 參數 useColumnsForParameterNames 後,你可以強制 它 OleDbCommandBuilder 根據欄位名稱產生參數。 此策略僅在滿足以下條件時成功:
ParameterNameMaxLength從 GetSchema 方法呼叫回傳且集合中DataSourceInformation找到的 已被指定,其長度等於或大於產生的參數名稱。
產生的參數名稱符合從 GetSchema 方法呼叫回傳並可在DataSourceInformation集合正規表達式中找到的條件ParameterNamePattern。
ParameterMarkerFormat從 GetSchema 方法呼叫回傳且在集合中找到DataSourceInformation的 A 被指定為
如需詳細資訊,請參閱使用 CommandBuilder 產生命令。