使用插入更新删除的3tier体系结构 [英] 3tier Architecture using insert update delete

查看:67
本文介绍了使用插入更新删除的3tier体系结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用3层体系结构来进行插入更新删除操作.
我想在插入操作中为prod_id生成编号.
plz答复任何人

I am using 3 tier architecture for using insert update delete operations..
i want to generate number for prod_id in insert operation.
plz reply anyone

推荐答案

在这种情况下生成唯一ID是数据库的工作.您不应该尝试手动创建prod_id值

您没有提到正在使用什么数据库,我将假设使用SQL Server.

*您可能有一个产品"表或类似的表.如果prod_id是唯一标识符(主键),则将列设置为具有IDENTITY规范.每次您现在插入表时,SQL Server都会自动生成下一个可用的ID

*插入表后,您可以使用SCOPE_IDENTITY()函数访问SQL生成的值(您使用的是原始ADO.net吗?还是像实体框架这样的ORM?)
Generating unique IDs in this context is the job of the database. You shouldn''t be trying to manually create the prod_id value

You haven''t mentioned what database you are using, I''m going to assume SQL Server.

* You probably have a ''Products'' table or something like that. If prod_id is the unique identifier (primary key), then set the column to have the IDENTITY specification. Every time you insert into the table now, SQL Server will automatically generate the next available ID

* After inserting into the table, you can access the value that was generated by SQL by using the SCOPE_IDENTITY() function (are you using raw ADO.net? or an ORM like Entity Framework?)


这是一篇很棒的文章,将帮助您单击此处
http://www.dotnetfunda.com/articles/article71.aspx [
this is a great artical will helps you click here
http://www.dotnetfunda.com/articles/article71.aspx[^]


您可以通过两种方式进行操作

1)将prod_id存储在全局类中,并在插入
之前将其递增1
2)将所有数据(没有prod_id)传递到数据库,然后从数据库中找到最大的prod_id并在过程
中递增
尽管第一种方法可以正常工作,但我更喜欢第二种方法.
you can do this by two way

1 ) store your prod_id in global class and increment it by one before insert

2 ) pass your all data(without prod_id ) to database and after that find max existing prod_id from database and increment there in procedure

although first method is work fine but i prefer second method more.


这篇关于使用插入更新删除的3tier体系结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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