如何在asp.net中显示数据库中的数据 [英] How to display the data from database in asp.net

查看:270
本文介绍了如何在asp.net中显示数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends,



我正在使用asp.net,我的项目中有两页。



第一页是登录页面

第二页是根据登录下拉选择从数据库中检索数据。



在第一页(登录)我有Dropdownlist(departmentList)和Textbox(密码)

和一个登录按钮。



用户将从下拉菜单中选择部门然后他输入密码,然后点击登录按钮。

当用户点击登录按钮时,在第二页我有3个文本框,根据下拉列表从数据库中检索数据。



在数据库中,我在这些字段中存储了数据,



Dept_code,密码,工资,TelephoneNo,ManagerName。(TableName DeptInfo) )



Dept_code - IT(这将显示在下拉列表(loginPage)中)

密码 - 用于登录

薪水 - 这应该显示在船尾的文本框中呃登录(它必须从数据库中检索)

电话 - 这也应该在登录后显示在文本框中(它必须从数据库中检索)

管理员名称 - 这也应该显示在登录后的文本框(必须从数据库中检索)





请帮助我,如何解决这个问题。



我已经完成了登录页面,现在在第二页有文本框。



请帮忙。



谢谢。

Hello Friends,

am working on asp.net, i have two pages in my project.

first page is login page
second page is retrieve data from database based on login dropdown selection.

In first page(Login Page) I have Dropdownlist(departmentList) and Textbox(password)
and a login button.

User will select the department from dropdown and then next he enters the password, and clicks on login button.
When User clicks on login button, In second page I have 3 textboxes to retrieve data from database according to dropdownlist.

In database I have Stored data with in these fields,

Dept_code,Password,Salary,TelephoneNo,ManagerName.(TableName DeptInfo)

Dept_code - IT (This will display in dropdownlist(loginPage) )
Password - This is used for login
Salary - this should display in textbox after login( it must retrieve from DB)
Telephone - this should also display in textbox after login ( it must retrieve from DB)
Manager Name - this should also display in textbox after login ( it must retrieve from DB)


Please can you help me , how to solve this.

already i have completed login page , and now am in second page with textboxes.

Please help.

THANKS.

推荐答案

您可以执行以下操作:


$首页上的b $ b(登录):



您需要将您的下拉选择值放入会话中以将其移至下一页。



成功登录后:在第二页上,您首先需要从会话中获取该值。然后是以下......

you can do the following:

on First Page(Login) :

you need to put your dropdown selectedValue in session to move it to the next page.

after successfull login: On second page you first need to get that values from session. and Then you the following...
<pre lang="cs">
string sessValue = Conver.ToString(Session["youSessionName"]);
youConectionName.Open();
SqlCommand cmd = new SqlCommand("Select * from DeptInfo where DeptCode='" + sessValue + "'", youConectionName);

SqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            Salary.Text  = rd["Salary"].ToString();
            Telephone.Text =rd["TelephoneNo"].ToString();
            Manager Name.Text=rd["ManagerName"].ToString();
        }
        else
        {
            //Code will reach here if no records found.
        }
</pre>







您可以在页面加载或按钮点击时调用此项你想要...



这肯定会帮助你......




you can call this on page load or on button click as you want...

This will definately help you....


这篇关于如何在asp.net中显示数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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