用于在datagrid中插入要存储在SQL数据库中的行的行索引 [英] Row Index for Inserting rows in datagrid to be stored in SQL database

查看:64
本文介绍了用于在datagrid中插入要存储在SQL数据库中的行的行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的VB窗体应用程序中有一个datagridview,它绑定到数据集并写入SQL数据库。必须将屏幕上项目的顺序保存到数据库中,以便按照用户保存它们的顺序检索它们。我目前
有一个整数类型的行索引列。当用户添加行时,第一行自动编号为100.添加的每个附加行的增量为100.但是,如果用户插入行,则在原始行之间编号。因此,如果您在
100和200之间插入,则行编号为150.如果再次插入100和新150之间,则行编号为125,依此类推。一旦不能再分割不同的内容,整个列表将从头开始重新编号。我试图提出一种方法,将
限制重新编号的次数或完全消除它。如果有几百行,这个重新编号会强制将它们全部写回数据库,这是一个昂贵且可能很长的过程。


我可以将行数数千或数万或者将数据类型更改为十进制,但这两种方法都有局限性。


任何建议都将不胜感激。

解决方案

您好Technobeam,


- >必须将屏幕上项目的顺序保存到数据库中,以便按照与该数据库相同的顺序检索它们。用户保存了它们。


我建议您在保存项目时将当前时间与项目一起使用。然后根据从数据库中检索数据的时间对其进行排序。


最好的问候,

Youjun Tang



I have a datagridview in my VB windows forms application that is bound to a dataset and written to a SQL database. The order of the items on the screen must be saved to the database so they can be retrieved in the same order that the user saved them. I currently have a row index column of type integer. when a user adds a row the first row is automatically numbered 100. each additional row added is in increments of 100. However, if a user inserts a row it is numbered in between the original rows. so if you insert between 100 and 200 the row is numbered 150. If you insert again between 100 and the new 150 the row is numbered 125 and so on. Once the different can no longer be split, the entire list is re-numbered from the beginning. I'm trying to come up with a method that will limit the number of times renumbering occurs or eliminate it completely. If there are several hundred rows, this renumbering forces them all to be written back to the database which is an expensive and potentially lengthy process.

I can number the rows by thousands or tens of thousands or change the data type to decimal but both of these methods have limitations.

Any suggestions would be greatly appreciated.

解决方案

Hi Technobeam,

-->The order of the items on the screen must be saved to the database so they can be retrieved in the same order that the user saved them.

I suggest you using the currenttime with the item when saving the items. then sort it with the time when you retrieve the data from the database.

Best regards,
Youjun Tang


这篇关于用于在datagrid中插入要存储在SQL数据库中的行的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆