我如何在新的pagg(page_load事件)中检索信息? [英] how can i retrieve infromation in new pagg(page_load event) ?

查看:66
本文介绍了我如何在新的pagg(page_load事件)中检索信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在新页面中从数据库中检索信息,这是指当页面调用自动显示的信息时.
前任.就像用户个人资料一样(登录时,我们的信息将来自数据库)
plz help

i want to retrieve information from database in new page means when page called the information shown automatically.
ex. like user profile(when we login our information will come from database)
plz help

推荐答案

检查此示例代码....我希望它对您有用....


check this sample code....i hope it work for you....


private void btnLogin_Click(object sender, EventArgs e)
        {
            

                
                counter = counter + 1;
                try
                {

                    //SqlConnection con = new SqlConnection();
                    //con.ConnectionString = "Data Source=######; Initial Catalog=


;用户ID = sa;密码= @@@@@@@@@; // con.Open(); Program.Connection2Server(); 字符串查询= " + cboUser.Text + '"; SqlCommand cmd = SqlCommand(query,Program.con); SqlDataReader dr = cmd.ExecuteReader(); Dr.Read(); 字符串 s1 = dr [ 0 ].ToString().Trim(); 字符串 s2 = dr [ 1 ].ToString().Trim(); 如果((s1 == cboUser.Text)&&(s2 == txtpassword.Text)) { MessageBox.Show(" ); 如果(cboUser.Text == " 跨度>) { 管理员广告= Admin(); .Hide(); ad.Show(); } 其他 如果(cboUser.Text == " 教师") { Faculty fac = Faculty(); .Hide(); fac.Show(); } 其他 如果(cboUser.Text == " 帐户") { 帐户acc = Accounts(); .Hide(); acc.Show(); } 其他 如果(cboUser.Text == " 学生") { 学生st = Students(); .Hide(); st.Show(); } Program.con.Close(); } 其他 { MessageBox.Show(" ); txtpassword.Clear(); txtpassword.Focus(); } Program.con.Close(); } 捕获(SqlException se) { MessageBox.Show(" + se.ToString()); } }
; User ID=sa; Password=@@@@@@@@@"; //con.Open(); Program.Connection2Server(); string query = "select * from Users_Password where UserName='" + cboUser.Text + "'"; SqlCommand cmd = new SqlCommand(query,Program.con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); string s1 = dr[0].ToString().Trim(); string s2 = dr[1].ToString().Trim(); if ((s1 == cboUser.Text) && (s2 == txtpassword.Text)) { MessageBox.Show("Login Succesfull"); if (cboUser.Text == "Admin") { Admin ad = new Admin(); this.Hide(); ad.Show(); } else if (cboUser.Text == "Faculty") { Faculty fac = new Faculty(); this.Hide(); fac.Show(); } else if (cboUser.Text == "Accounts") { Accounts acc = new Accounts(); this.Hide(); acc.Show(); } else if (cboUser.Text == "Students") { Students st = new Students(); this.Hide(); st.Show(); } Program.con.Close(); } else { MessageBox.Show("Login Failed"); txtpassword.Clear(); txtpassword.Focus(); } Program.con.Close(); } catch (SqlException se) { MessageBox.Show("Error in Sql Connection" + se.ToString()); } }


这篇关于我如何在新的pagg(page_load事件)中检索信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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