获取或设置用来将新记录插入数据库中的 SQL 语句或存储过程。
[Visual Basic]
Public Property InsertCommand As DB2Command
[C#]
public new DB2Command
InsertCommand {get; set;}
[C++]
public: __property DB2Command
* get_InsertCommand();
public: __property void set_InsertCommand(DB2Command
*);
[JScript]
public function get InsertCommand() : DB2Command
;
public function set InsertCommand(DB2Command
);
在更新操作期间用来插入数据库中与 DataSet 中新行相对应的记录的 DB2®Command。
将 InsertCommand 属性指定给先前创建的 DB2Command 对象时,将不克隆该 DB2Command。相反,InsertCommand 将保持对先前创建的 DB2Command 的引用。
在更新操作期间,如果未设置 InsertCommand 并且 DataSet 中包含主键信息,那么可以使用 DB2CommandBuilder 类来自动生成 InsertCommand 和使 DataSet 与数据库相一致所需的其他命令。为此,请设置 DB2DataAdapter 的 SelectCommand 属性。生成逻辑还要求 DataSet 中存在键列信息。有关更多信息,请参阅 Microsoft(R) .NET Framework SDK 文档中的“自动生成的命令”。
[Visual Basic, C#] 以下示例将创建 DB2DataAdapter 并设置它的某些属性。
[Visual Basic]
Public Sub CreateDB2DataAdapter()
Dim mySelectText As String = _
"SELECT * FROM STAFF ORDER BY ID"
Dim myConnString As String = _
"DATABASE=SAMPLE;"
Dim myDataAdapter As New DB2DataAdapter(mySelectText, myConnString)
Dim myDataAdapter.InsertCommand As New DB2Command(
"INSERT INTO STAFF
VALUES ( 360, 'Johnson',84,'Clerk',2,11500.00, 100.00)", myConnString)
End Sub
[C#]
public void CreateDB2DataAdapter ()
{
string mySelectText = "SELECT * FROM STAFF ORDER BY ID";
string myConnString = "DATABASE=SAMPLE;";
DB2DataAdapter myDataAdapter = new DB2DataAdapter(mySelectText,myConnString);
myDataAdapter.InsertCommand = new DB2Command(
"INSERT INTO STAFF
VALUES ( 360, 'Johnson',84,'Clerk',2,11500.00, 100.00)", myConnString);
}