且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除过程后重新排序主键

更新时间:2023-12-05 20:48:40

主键用于将表连接在一起并建立索引,而不是用于人类.重新排列主键列可能会孤立数据,并严重破坏您的查询.

在表中添加另一列,然后将其重新排序(向用户显示该列而不是主键).
Primary keys are meant to be used for joining tables together and indexing, they are not meant to be used for human usage. Reordering primary key columns could orphan data and wreck havoc to your queries.

Add another column to your table and reorder that column to your will (show that column to your user instead of the primary key).


您好,

无需重新排列主键,ListBox具有两个属性(值和文本),将主键字段(ID)绑定到value属性,并在删除记录后重新绑定网格.

this.listBox1.DataSource = listToBind;
this.listBox1.DisplayMember =文本";
this.listBox1.ValueMember ="Id";

您可以使用属性来检索选定的值.

ListBox1.SelectedValue

希望对您有帮助.

谢谢!!!
Hi,

No need to rearrange the Primary key, ListBox has two properties( value and text), bind the primary key field(ID) to value property and rebind the grid after deleting the records.

this.listBox1.DataSource = listToBind ;
this.listBox1.DisplayMember = "Text";
this.listBox1.ValueMember = "Id";

You can retrieve the selected value using the property.

ListBox1.SelectedValue

Hope this will help you.

Thanks!!!