如何在asp.net网站上用sql server一次管理多个请求。 [英] how to manage multiple request at one time with sql server in asp.net website.

查看:61
本文介绍了如何在asp.net网站上用sql server一次管理多个请求。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在sql server数据库表中插入记录。

表结构

Sno int,

名称varchar,
companycode int。

i希望在网页请求的响应中通过公司代码识别sno。

如公司代码1是一个然后sno从1,2开始,3,4 ... so.same为另一个公司代码。

我的问题是当我同时请求表时,同样没有生成。

i have还尝试了存储过程但是当一次生成多个请求时它会失败。

请帮我解决这个问题。

i want to insert record in the sql server database table.
table structure
Sno int,
name varchar,
companycode int.
i want recognize sno by company code at the response on web request.
like company code 1 is one then sno start from 1,2,3,4...so on.same for another company code.
my problem is when i am requesting table at same time then same no is generated.
i had also tried stored procedure but it fails when multiple request generated at a time.
please help me to resolve this issue.

推荐答案

更改表设计。

将Sno设置为每行递增的主键 - http://technet.microsoft.com/en-us/library/ms189039.aspx [ ^ ]。



如果你不希望Sno成为主键,你仍然可以让它自动增加 - http://technet.microsoft.com/en-us/library/aa933196%28v=sql.80%29.aspx [ ^ ]。
Change the table design.
Set the Sno as a primary key that increments for every row - http://technet.microsoft.com/en-us/library/ms189039.aspx[^].

If you do not want Sno to be a primary key, you can still make it increment automatically - http://technet.microsoft.com/en-us/library/aa933196%28v=sql.80%29.aspx[^].


试试做这样的事情。





Try to do something like this.


DECLARE @MAX_sno int=null;
SELECT @MAX_sno=MAX(person_id) FROM TABLENAME WHERE companycode='Your_companycode'   ;
SET @MAX_sno=@MAX_sno+1;

----In MAX_sno you will get new sno value which can be used for new record insertion 


这篇关于如何在asp.net网站上用sql server一次管理多个请求。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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