在C#或SQL中自动生成序列号 [英] Auto generation of a sequence number in c# or SQL

查看:223
本文介绍了在C#或SQL中自动生成序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一种情况,用户输入的数字长度为9位数字。但是有些人只会输入901之类的三位数。因此,当他们在文本框中输入三位数时,我必须自动生成其余6位数并将其插入数据库中。我应该对照数据库表检查这是什么,最后一个自动生成的数字是901,然后向其插入下一个值。
我只需要一个建议而不是完整的解决方案,我应该执行此C#或SQL。

I have a situation where user enters a number of length 9 digits. But some people will only enter three digits like 901. So when they enter three digits in the text box, i have to auto generate the rest of the 6 digits and insert it into the database. I should check this against data base table that what was the last auto generated number with 901 and insert next value to it. I just need a suggestion not the complete solution, that i should do this c# or SQL. Which is the best way to do it.

谢谢

推荐答案

一些东西。正如Tim所提到的,似乎系统应该为用户提供号码,而不是用户为系统提供号码。无论如何,您都希望使用一个至少包含一系列主键[http://en.wikipedia.org/wiki/Unique_key](数字不可重复)的数据库。选择自动递增的键。这样可以确保没有其他用户具有相同的编号/ ID。

A few things. As Tim mentioned, seems the system should provide the user with the number, not the user providing the system with the number. At any rate you'll want to use a database which would at the least contain a series of primary keys [http://en.wikipedia.org/wiki/Unique_key] (numbers not to be duplicated). Se the key to auto increment. This will ensure no other user has the same number/id.

这篇关于在C#或SQL中自动生成序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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