DataRows with no primary key, and listbox items
-
Hello all. I'm working on a portion of a program I'm writing that involves creating new rows in a table that has no primary key and two foreign keys. The rows in the datatable are invoice details for rented items. I want to be able to get this new row and place it's contents in a listbox, followed up by a number of similar new rows in the same listbox. I'm not sure how (if it's possible,) to retrieve the new row since it has no primary key. I'm also not sure then how to associate the datarow with it's respective item in the listbox. My hope is to be able to, when necessary, select the item in the listbox and use it to delete the row it's associated with from the datatable. I'm going out on a limb here hoping someone might have some advice or can point me in the right direction. Any help would be hugely appreciated. Thanks in advance!
-
Hello all. I'm working on a portion of a program I'm writing that involves creating new rows in a table that has no primary key and two foreign keys. The rows in the datatable are invoice details for rented items. I want to be able to get this new row and place it's contents in a listbox, followed up by a number of similar new rows in the same listbox. I'm not sure how (if it's possible,) to retrieve the new row since it has no primary key. I'm also not sure then how to associate the datarow with it's respective item in the listbox. My hope is to be able to, when necessary, select the item in the listbox and use it to delete the row it's associated with from the datatable. I'm going out on a limb here hoping someone might have some advice or can point me in the right direction. Any help would be hugely appreciated. Thanks in advance!
Lodeclaw wrote:
I'm writing that involves creating new rows in a table that has no primary key and two foreign keys
Isn't there any natural key present? Also could you create a key column in your datatable and let the datatable to generate a unique value to it?
Lodeclaw wrote:
followed up by a number of similar new rows in the same listbox
How do you recognize similarity?
Lodeclaw wrote:
I'm also not sure then how to associate the datarow with it's respective item in the listbox
If I understood correctly your problem in this, you would use ValueMember[^] definition in your binding.
Lodeclaw wrote:
use it to delete the row it's associated with from the datatable
When the listbox is binded to the datatable, you would actually delete the row from the datatable. The listbox reflects the changes in your datatable.
The need to optimize rises from a bad design.My articles[^]