自发电 [英] Autogeneration

查看:59
本文介绍了自发电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我正在以存款方详细信息"形式使用存款方ID",该表格已连接到存款方详细信息" SQL表....

我为Dep_ID使用了主键",希望大家知道什么是主键"

我的问题是

我必须自动生成"存款人ID ...我使用了几种方法来从存款人详细信息SQl表生成数字,例如,

1.)count(Dep_ID)+1(在选择查询中)和

2.)isnull(max(Dep_ID),0)+1

但没有用..

谁能用C#编码建议我

Hi...

I am Using a "Depositor ID",in my "Depositor Details" form which is connected to "depositor details" SQL table....

I am using a "Primary key" for Dep_ID, I hope all you know what is "Primary key"

and my problem is

I have to "autogenerate" the depositor ID... I have used several ways for generating the number from Depositor details SQl table such as,

1.)count(Dep_ID)+1(in select Query) and

2.)isnull(max(Dep_ID),0)+1

but no use of it..

can anyone please suggest me with C# coding

推荐答案

为什么不将其设置为自动递增列呢?当您插入新记录时,数据库将为您自动增加数据库.您可以让存储的proc返回生成的ID(或插入的记录,其中包含自动递增的ID.)
Why don''t you just set it as an auto-incrementing column? The database will auto-increment it for you when you insert a new record. You can have the stored proc return the generated ID (or the inserted record which includes the auto-incremented ID.


只需设置表即可为您执行此操作.手动生成主键

在SQL Server中,可以通过将身份"字段设置为true来实现.
Just set the table to do this for you. You shouldn''t be generating primary keys manually

In SQL Server this is achieved by setting the ''Identity'' field to true


如果您使用的是SQL Server,请使用一个身份列
如果您使用的是Oracle,请使用序列生成密钥

无论您做什么,它都必须在原子工作单元中发生,这是数据库所理解的.以上建议是实现此目标的简便方法.

问候
Espen Harlinn
If you are on SQL Server use an identity column
If you are on Oracle use a sequence to generate your keys

Whatever you do it has to happen in an atomic unit of work, as understood by the database. The above proposals are the easies way to accomplish this ...

Regards
Espen Harlinn


这篇关于自发电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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