如何在asp.net中显示数据库中的数据

编程入门 行业动态 更新时间:2024-10-27 08:36:21
本文介绍了如何在asp中显示数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Hello Friends, 我正在使用asp,我的项目中有两页。 第一页是登录页面 第二页是根据登录下拉选择从数据库中检索数据。 在第一页(登录)我有Dropdownlist(departmentList)和Textbox(密码) 和一个登录按钮。 用户将从下拉菜单中选择部门然后他输入密码,然后点击登录按钮。 当用户点击登录按钮时,在第二页我有3个文本框,根据下拉列表从数据库中检索数据。 在数据库中,我在这些字段中存储了数据, Dept_code,密码,工资,TelephoneNo,ManagerName。(TableName DeptInfo) ) Dept_code - IT(这将显示在下拉列表(loginPage)中) 密码 - 用于登录 薪水 - 这应该显示在船尾的文本框中呃登录(它必须从数据库中检索) 电话 - 这也应该在登录后显示在文本框中(它必须从数据库中检索) 管理员名称 - 这也应该显示在登录后的文本框(必须从数据库中检索) 请帮助我,如何解决这个问题。 我已经完成了登录页面,现在在第二页有文本框。 请帮忙。 谢谢。

Hello Friends, am working on asp, 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中显示数据库中的数据

本文发布于:2023-10-23 23:12:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   数据   如何在   net   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!