dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2CommandBuilder Class / KeyFields Property
Example

In This Topic
    KeyFields Property (DB2CommandBuilder)
    In This Topic
    Gets or sets string containing list of key field names separated by semicolon. They are used to generate update commands.
    Syntax
    'Declaration
     
    Public Shadows Property KeyFields As String
    public new string KeyFields {get; set;}

    Property Value

    The string containing list of key field names separated by semicolon.
    Remarks

    This property is used when the ConflictOption property is set to OverwriteChanges, otherwise all columns will be used in the WHERE clause.

    If KeyFields is nonempty, its value is used as the list of columns for the WHERE clause. If KeyFields is empty, the primary key columns are used.

    Example
    The following example demonstrates how UPDATE and DELETE statements are generated.
    public void UseKeyFields(string connectionString) {
    
            DB2Connection conn = new DB2Connection(connectionString);
            conn.Open();
    
            DB2DataAdapter adapter = new DB2DataAdapter("SELECT * FROM Dept", conn);
            DB2CommandBuilder commBuilder = new DB2CommandBuilder(adapter);
    
            commBuilder.ConflictOption = ConflictOption.OverwriteChanges;
    
            commBuilder.KeyFields = "DeptNo, DName";
    
            string updateComm = commBuilder.GetUpdateCommand().CommandText;
            string deleteComm = commBuilder.GetDeleteCommand().CommandText;
    
            Console.WriteLine(updateComm);
            Console.WriteLine(deleteComm);
            conn.Close();
    }
    Public Sub UseKeyFields(ByVal connectionString As String)
            Dim conn As DB2Connection = New DB2Connection(connectionString)
            conn.Open()
    
            Dim adapter As DB2DataAdapter = New DB2DataAdapter("SELECT * FROM Dept", conn)
            Dim commBuilder As DB2CommandBuilder = New DB2CommandBuilder(adapter)
    
            commBuilder.ConflictOption = ConflictOption.OverwriteChanges
    
            commBuilder.KeyFields = "DeptNo, DName"
    
            Dim updateComm As String = commBuilder.GetUpdateCommand().CommandText
            Dim deleteComm As String = commBuilder.GetDeleteCommand().CommandText
    
            Console.WriteLine(updateComm)
            Console.WriteLine(deleteComm)
            conn.Close()
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also