开发者

Auto incrementing of id and showing it in the textbox in 3 tier architecture

开发者 https://www.devze.com 2023-03-25 01:48 出处:网络
I am using Visual Studio 2008, ASP.NET 3.5 and C# for my project. I am use 3-tier architecture for database connectivity.I have designed a form with the ID, name, age, etc.In the database table, id is

I am using Visual Studio 2008, ASP.NET 3.5 and C# for my project. I am use 3-tier architecture for database connectivity. I have designed a form with the ID, name, age, etc. In the database table, id is the prima开发者_JAVA百科ry key. On the page load I want to display the next value of the id in the text box automatically. Then the user would have to enter the other details such as name, age and so on. After which, I want to submit the data to the table. Can any one suggest a good idea for this. I am new to 3 tiered architecture.


You can make use of the max function and get the maximum value of the increment column but the problem arise when there are multiple requests are there.

So to handle this case you can store the value in the static variable once and than increment the value of it.

but it still cause problem if some once cancel the submit.

So you need to check out the database and require to poll the maximum value at regual interval and have to check with the static varaible and have to do update accordingly.

Basically you need to define your algoritham to do this in smoother way.


First you get the maximum value from id column

select max(id) from TableName

then increment it by 1 and set this value to textbox


It is not a good idea to show for user Id from your data base from security point of view in our project if we need to send to UI Id the Id before encrypted. In your case I think if Id is auto generated by SQL it is not need to display on view. any way you should avoid to display not encrypted Ids


This is pretty basic stuff, writing entity code and database layer connection code and all that is very common and is pretty much identical from one project to the next. Coding it all manually is error prone and time consuming and completely unnecessary. I would seriously suggest code generation with tools like codesmith using something like the nettiers framework.

And I don't know why you would actually want to show the ID on the forms. The proper way would be using the forms to fill an entity, and then using the data layer to save that entity. In a framework like nettiers, whether it's a new or updated or changed entity is tracked, and the framework handles all the proper database calls. You never need to really know about the ID except when you need to read the data back in from the database. But the entity returned from the data layer should already have the new ID set after the save.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号