DbCommandBuilder.GetUpdateCommand 方法

定义

获取在数据源中执行更新操作所需的自动生成的 DbCommand 对象。Gets the automatically generated DbCommand object required to perform updates at the data source.

重载

GetUpdateCommand()

获取在数据源中执行更新操作所需的自动生成的 DbCommand 对象。Gets the automatically generated DbCommand object required to perform updates at the data source.

GetUpdateCommand(Boolean)

获取对数据源执行更新操作所必需的自动生成的 DbCommand 对象,可选择使用列作为参数名。Gets the automatically generated DbCommand object required to perform updates at the data source, optionally using columns for parameter names.

注解

应用程序可以使用 GetUpdateCommand 方法进行信息性或故障排除,因为它返回要执行的 DbCommand 对象。An application can use the GetUpdateCommand method for informational or troubleshooting purposes because it returns the DbCommand object to be executed.

您还可以将 GetUpdateCommand 用作修改后的命令的基础。You can also use GetUpdateCommand as the basis of a modified command. 例如,你可以调用 GetUpdateCommand 和修改命令文本,然后在 DbDataAdapter上显式设置。For example, you might call GetUpdateCommand and modify the command text, and then explicitly set that on the DbDataAdapter.

首次生成 SQL 语句后,如果应用程序以任何方式更改语句,则必须显式调用 RefreshSchemaAfter the SQL statement is first generated, the application must explicitly call RefreshSchema if it changes the statement in any way. 否则,GetUpdateCommand 仍将使用前一语句中的信息,这可能是不正确的。Otherwise, the GetUpdateCommand will still be using information from the previous statement, which might not be correct. 当应用程序调用 UpdateGetUpdateCommand时,将首先生成 SQL 语句。The SQL statements are first generated either when the application calls Update or GetUpdateCommand.

生成参数名称时,默认行为是使用各种参数 @p1@p2等。The default behavior, when generating parameter names, is to use @p1, @p2, and so on for the various parameters. 如果 GetUpdateCommand 的重载版本允许您指定此行为,则可以使 DbCommandBuilder 改为基于列名称生成参数。If the overloaded version of GetUpdateCommand allows you to specify this behavior, you can cause the DbCommandBuilder to generate parameters based on the column names instead.

GetUpdateCommand()

获取在数据源中执行更新操作所需的自动生成的 DbCommand 对象。Gets the automatically generated DbCommand object required to perform updates at the data source.

public:
 System::Data::Common::DbCommand ^ GetUpdateCommand();
public System.Data.Common.DbCommand GetUpdateCommand ();
member this.GetUpdateCommand : unit -> System.Data.Common.DbCommand
Public Function GetUpdateCommand () As DbCommand

返回

自动生成的、执行更新所需的 DbCommand 对象。The automatically generated DbCommand object required to perform updates.

注解

应用程序可以使用 GetUpdateCommand 方法进行信息性或故障排除,因为它返回要执行的 DbCommand 对象。An application can use the GetUpdateCommand method for informational or troubleshooting purposes because it returns the DbCommand object to be executed.

您还可以将 GetUpdateCommand 用作修改后的命令的基础。You can also use GetUpdateCommand as the basis of a modified command. 例如,你可以调用 GetUpdateCommand 和修改命令文本,然后在 DbDataAdapter上显式设置。For example, you might call GetUpdateCommand and modify the command text, and then explicitly set that on the DbDataAdapter.

首次生成 SQL 语句后,如果应用程序以任何方式更改语句,则必须显式调用 RefreshSchemaAfter the SQL statement is first generated, the application must explicitly call RefreshSchema if it changes the statement in any way. 否则,GetUpdateCommand 仍将使用前一语句中的信息,这可能是不正确的。Otherwise, the GetUpdateCommand will still be using information from the previous statement, which might not be correct. 当应用程序调用 UpdateGetUpdateCommand时,将首先生成 SQL 语句。The SQL statements are first generated either when the application calls Update or GetUpdateCommand.

另请参阅

GetUpdateCommand(Boolean)

获取对数据源执行更新操作所必需的自动生成的 DbCommand 对象,可选择使用列作为参数名。Gets the automatically generated DbCommand object required to perform updates at the data source, optionally using columns for parameter names.

public:
 System::Data::Common::DbCommand ^ GetUpdateCommand(bool useColumnsForParameterNames);
public System.Data.Common.DbCommand GetUpdateCommand (bool useColumnsForParameterNames);
member this.GetUpdateCommand : bool -> System.Data.Common.DbCommand
Public Function GetUpdateCommand (useColumnsForParameterNames As Boolean) As DbCommand

参数

useColumnsForParameterNames
Boolean

如果为 true,则生成与列名匹配的参数名(如果可能)。If true, generate parameter names matching column names, if possible. 如果为 false,则生成 @p1@p2,以此类推。If false, generate @p1, @p2, and so on.

返回

自动生成的、执行更新所需的 DbCommand 对象。The automatically generated DbCommand object required to perform updates.

注解

应用程序可以使用 GetUpdateCommand 方法进行信息性或故障排除,因为它返回要执行的 DbCommand 对象。An application can use the GetUpdateCommand method for informational or troubleshooting purposes because it returns the DbCommand object to be executed.

您还可以将 GetUpdateCommand 用作修改后的命令的基础。You can also use GetUpdateCommand as the basis of a modified command. 例如,你可以调用 GetUpdateCommand 和修改命令文本,然后在 DbDataAdapter上显式设置。For example, you might call GetUpdateCommand and modify command text, and then explicitly set that on the DbDataAdapter.

首次生成 SQL 语句后,如果应用程序以任何方式更改语句,则必须显式调用 RefreshSchemaAfter the SQL statement is first generated, the application must explicitly call RefreshSchema if it changes the statement in any way. 否则,GetUpdateCommand 仍将使用前一语句中的信息,这可能是不正确的。Otherwise, the GetUpdateCommand will still be using information from the previous statement, which might not be correct. 当应用程序调用 UpdateGetUpdateCommand时,将首先生成 SQL 语句。The SQL statements are first generated either when the application calls Update or GetUpdateCommand.

生成参数名称时,默认行为是使用各种参数 @p1@p2等。The default behavior, when generating parameter names, is to use @p1, @p2, and so on for the various parameters. 通过传递 useColumnsForParameterNames 参数的 true,可以强制 DbCommandBuilder 根据列名来改为生成参数。Passing true for the useColumnsForParameterNames parameter allows you to force the DbCommandBuilder to generate parameters based on the column names instead. 仅当满足以下条件时,基于列名生成参数才会成功:Generation of the parameters based on column names succeeds only if the following conditions are met:

另请参阅

适用于