从db显示文本框中的值 [英] Display a value in textbox from db

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

问题描述

我们如何在文本框中实现最高值,在页面加载中增加1



我尝试过:



How can we implement a highest value in textbox which is increment by 1 in page load

What I have tried:

protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }
            txt_id= ('SELECT MAX(unitid) + 1  from tblunitmaster');
}

推荐答案

我们不能像上面的逻辑那样做。如果您在页面加载中编写代码而没有任何条件,那么当您回发时它将被执行。



步骤1:在回发后第1次验证是否它是一个登录或回发。

步骤2:然后从数据库中获取值并在本地变量/ Session中设置它并增加数据库中的计数。

步骤3:将此逻辑分成另一个类或函数,以确保代码清晰可读。







We cannot do like the above logic. If you write the code in the page load with out any conditions then when ever you post back it will be executed.

Step 1 : In post-back 1st verify if it is a login or a post back.
Step 2 : Then get the value from the Database and set that in a local variable/Session and increase the count in the database.
Step 3 : Separate this logic into a another class or a function to make sure the code is clean and readable.



txt_id= ('SELECT MAX(unitid) + 1 from tblunitmaster');

- >你必须使用SQL服务器连接来连接数据库。



如果这个dint解决了你的目的请回复并解释你的要求。清晰。在此先感谢:)

--> you have to use SQL server connection to connect to the database.

If this dint solve your purpose please reply and explain you req. clearly. Thanks in advance :)


使用 ExecuteScalar [ ^ ]从数据库读取数据并在任何UI控件上显示。

查看 Page.IsPostBack Property [ ^ ]自 page_Load 当页面中有回发时会触发事件,而后者会增加文本框中的值。
use ExecuteScalar [^] to read the data from db and display it on any UI control.
have a look on Page.IsPostBack Property [^] since the page_Load event will be fired when there is post back in the page which in turn, will increment the value in the textbox.


这篇关于从db显示文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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