查询出来一个SqlDataReader的第一行第一列怎么绑定到Label上 RT 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 while(dr.Read()){Response.write(dr["UserName"]}dr.close();以下是用户登录判断时候合法用户的代码SqlConnection con = DB.WebConnection();//通过类调用连接上数据库con.Open();//打开连接SqlCommand com = new SqlCommand();com.CommandText = "Select * from Users where UserName='" + tbUserName.Text + "'";com.CommandType = CommandType.Text;com.Connection = con;SqlDataReader reader = com.ExecuteReader();if (reader.Read()){int UserID = reader.GetInt32(0);string Password = reader["UserPassword"].ToString();string Password0 = tbUserPassword.Text;if (Password == Password0){Session["uid"] = UserID;Session["name"] =tbUserName.Text;Response.Redirect("index.aspx");}else{Response.Redirect("login.aspx");}}else{Response.Redirect("login.aspx") 返回个DataTablethis.Label.Text=dt.Rows[0][0].ToString(); using(SqlDataReader sdr=....){while(sdr.read()){Label.text=sdr[0];break;}} this.Label.Text=dt.Rows[0][0].ToString();这样就可以了取第一行的第一列 列如果不确定 可以直接赋值 字段名字 老大 人家说的是sqldatareader 你那是datatable循环datareader中的行while(dr.read())取某一列dr[columnIndex] while(dr.read()){ this.labelId名称.text= dr[列的索引].tostring();} 你循环SQLDataReader的时候的第1次循环的数据就是你查出来的第一条,你要怎么绑就随便你自己了,如果第1条不是你想要的,那么就是SQL的问题,重新把SQL写一下把你想要的数据排到最前面吧! if(dr.read()){ labelId名称.text= dr["列名"].tostring();}第一行第一列的话labelId名称.text= dr[0].tostring(); if(dr.read()){ labelId名称.text= dr["列名"].tostring();}第一行第一列的话写索引也行 labelId名称.text= dr[0].tostring(); 你使用menu控件吗? 高手们,怎么把自己做好的网站打包,并一同把framework 一同打进去,一同安装 如何获得登录名和分组id? asp.net 中无法把最终的excel显示出来 一个奇怪的现象,捆饶了两天啊!!拿出来讨论一下! 关于web下调用process的问题 菜菜的一问:imagebutton事件问题 为了部署源码,如何新建网站而非虚拟目录 怎么截取一个字符串的前1/3呢? 如何让LinkButton相应回车键 C#字符串问题 求如何自定义处理SqlDataSource的插入异常。
{
Response.write(dr["UserName"]
}
dr.close();
以下是用户登录判断时候合法用户的代码
SqlConnection con = DB.WebConnection();//通过类调用连接上数据库con.Open();//打开连接SqlCommand com = new SqlCommand();
com.CommandText = "Select * from Users where UserName='" + tbUserName.Text + "'";
com.CommandType = CommandType.Text;
com.Connection = con;
SqlDataReader reader = com.ExecuteReader();
if (reader.Read())
{
int UserID = reader.GetInt32(0);
string Password = reader["UserPassword"].ToString();
string Password0 = tbUserPassword.Text;
if (Password == Password0)
{
Session["uid"] = UserID;
Session["name"] =tbUserName.Text;
Response.Redirect("index.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}
else
{
Response.Redirect("login.aspx")
{
while(sdr.read()){
Label.text=sdr[0];
break;
}
}
循环datareader中的行
while(dr.read())
取某一列
dr[columnIndex]
this.labelId名称.text= dr[列的索引].tostring();
}
labelId名称.text= dr["列名"].tostring();
}
第一行第一列的话
labelId名称.text= dr[0].tostring();
labelId名称.text= dr["列名"].tostring();
}
第一行第一列的话写索引也行
labelId名称.text= dr[0].tostring();