如何在ASP.NET中的文本框中获取数据库的值(即ID增量值) [英] how to get value of database (i.e. ID increment value) in textbox in ASP.NET

查看:171
本文介绍了如何在ASP.NET中的文本框中获取数据库的值(即ID增量值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有从表中获得Id的价值



我使用以下代码:

I am not getting value of Id from table

I am using following code :

DataTable dt = new DataTable();
if (dt.Rows.Count > 0)
  txtLinkID.Text = (Convert.ToInt32(dt.Rows[0]["link_id"]) + 1).ToString();
else
  txtLinkID.Text = "1";



告诉我如何在ASP.NET


So tell me how to get value of database (i.e. ID increment value) in textbox in ASP.NET

推荐答案

不要。



甚至不要考虑它。

为什么不呢?因为大多数数据库都是多用户系统,所以你不能依赖下一个值比当前最后一个值更大:所有需要的是另一个用户做同样的事情,整个系统崩溃就像一个纸牌屋。



只有在写入导致其变化的数据后才尝试获取自动变量的值。任何事先做过的尝试都会让你对一些可怕的,可怕的问题敞开大门,这些问题之后很难解决 - 特别是如果你在任何一点使用数据并导致错误值插入数据库中。确定哪些应该存在,哪些属于那里,事后是一场彻头彻尾的噩梦,浪费了大量的时间。
Don't.

Don't even think about it.
Why not? Because most databases are multi-user systems, so you can't rely on the "next" value being one greater that the current last value: all it takes is one other user to be doing the same thing, and the whole system falls apart like a house of cards.

Only ever try to get the value of an automatic variable after the data which causes it to change has been written. Any attempt to do it beforehand leave you wide open to some horrible, horrible problems which are extremely difficult to sort out afterwards - particularly if you use the data at any point and that causes bad values to be inserted in the DB. Working out which should be there and which belong over there after the fact is a total nightmare, and wastes huge amounts of time.


这篇关于如何在ASP.NET中的文本框中获取数据库的值(即ID增量值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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