我想在我的asp.net项目中检索标签中的最新更新用户详细信息, [英] i want to retrive latest update user detail in a label in my asp.net project,

查看:73
本文介绍了我想在我的asp.net项目中检索标签中的最新更新用户详细信息,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码..

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Configuration;

使用System.Data;

使用System.Data.SqlClient;



public partial class Default5:System.Web.UI.Page

{

string strconn = ConfigurationManager.ConnectionStrings [touchconnectionstring7]。ConnectionString;



string conny;

SqlCommand cmd;



protected void Page_Load(object sender,EventArgs e)

{



SqlConnection con = new SqlConnection(strconn);

con.Open();

string conny =select userid,FIRSTNAME,PASSWORD,EMAILID FROM registration WHERE userid = max(userid) ;

cmd = new SqlCommand(conny,con);

SqlDataReader dr = cmd.Execut eReader();

dr.Read();

Label1.Text = dr [FIRSTNAME]。ToString();

dr .Read();

Label2.Text = dr [PASSWORD]。ToString();

dr.Read();

Label3.Text = dr [EMAILID]。ToString();

dr.Read();

dr.Close();

con.Close();



}











}



这段代码不起作用的人帮忙我急。

this is mine code..
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class Default5 : System.Web.UI.Page
{
string strconn = ConfigurationManager.ConnectionStrings["touchconnectionstring7"].ConnectionString;

string conny;
SqlCommand cmd;

protected void Page_Load(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(strconn);
con.Open();
string conny = "select userid, FIRSTNAME, PASSWORD, EMAILID FROM registration WHERE userid= max(userid);
cmd = new SqlCommand(conny, con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Label1.Text = dr["FIRSTNAME"].ToString();
dr.Read();
Label2.Text = dr["PASSWORD"].ToString();
dr.Read();
Label3.Text = dr["EMAILID"].ToString();
dr.Read();
dr.Close();
con.Close();

}





}

this code is not working guys help me its urgent.

推荐答案

您需要使用while循环或每个循环来获取行数据;



更改下面的代码并尝试。



You need to use a while loop or for each loop to fetch the row data;

Change the code as below and try.

while (dr.Read())
            {
                Label1.Text = dr["FIRSTNAME"].ToString();
                Label2.Text = dr["PASSWORD"].ToString();
                Label3.Text = dr["EMAILID"].ToString();
            }







使用DataReader检查下面的msdn示例。



http:// msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.110%29.aspx [ ^ ]


这篇关于我想在我的asp.net项目中检索标签中的最新更新用户详细信息,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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