how do I change a field having PrimaryKey???

Dear All;
I want to change just a No Duplicate field in a Row having Primary Key. When i follow as given in MCAD/MCSD code snippet as follows:

Dim rowChange as DataRow
rowChange=m_dtContacts.Rows.Find(m_NextID-1)
 rowChange.Item("Workphone")="(555)222-90000)"

it threw an exception of type "Dublicate Key.."
Is there any helpfull tip for solving such problem

Thanks alot
 


Answer this question

how do I change a field having PrimaryKey???

  • Dominic Morin

    Thanks

    I 'll be on vacation for a month. I 'll join you as soon as i come back.

    Hasan


  • rldonnell

    Hi,


    Logically, yes. You must be able to edit a field with a PK, But not the PK Field itself. Although you could still edit it, but you must be sure that it doesn't conflict with other constraints.

    Could you please post a detailed code snippet So that I could repro it in my machine...







    cheers,


    Paul June A. Domag

  • jasi

    Thanks paul for your reply:

    I don't want to change the priamry key itself, i want to change any cell in the row which acceptduplicate values. When i change data and save it , the database considers it as a new row with a duplicate pk.
    I hope it is clear.
    The code snippet is here:

    Private
    Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click

    Dim rowChange As DataRow

    'Change a field in the row

    rowChange = m_dsBoxes.tblBoxes.Rows.Find(PK-accepts only integer)

    rowChange.Item("BoxID") = txtBoxNo.Text      'PK-stringtype(no duplicates)

    rowChange.Item("Area") = drpArea.SelectedItem.Text

    rowChange.Item("Entry_Date") = CDate(txtDate.Text)

    rowChange.Item("Amount") = txtAmount.Text

    m_adptBoxes.Update(m_dsBoxes)

    End Sub



  • Wellproc

    Hi,


    Try checking the RowState if its percieved as a newly created row. Also check the UpdateCommand if it has the right Update Statement...
    I don't currently have a VS in front of me now. I'll try your code as soon as I return to my office. I'll give you a follow up tomorrow...







    cheers,


    Paul June A. Domag

  • rgabel

    Thanks Paul for your reply:
    I don't want to remove the constraint, I want to edit only a cell (Duplicate) in the row  with the existing of the PK. Like modifying a profile of an employee, no need to remove his ID number.

    In data acceess, it is pemissible to edit the data in a DataGrid, with the existing of the PK.

    I hope the idea is clear.

    Thanks

  • vba-dev

    Hi,


    I think that your updated data might be in conflict with some existing ones, therefore triggering a constraint. If you want to remove your constraints to be able to add duplicate fields,

    _dataTable.Constraints.Clear();







    cheers,


    Paul June A. Domag

  • how do I change a field having PrimaryKey???