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

[393 byte] By [Hasan] at [2007-12-16]
# 1
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

PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
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

Hasan at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3
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

PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4
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

Hasan at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 5
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
PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 6
Thanks

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

Hasan

Hasan at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified