帮助阅读Label中的字段 [英] Help on read a field in Label
本文介绍了帮助阅读Label中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们.请看下面的代码(这是Windows窗体C#代码):
Hi friends. Look At below code(this is a windows form c# code):
DataSet ds = new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=localhost;initial catalog=univ;integrated security=true");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select name from students", con);
da.Fill(ds, "students");
label1.DataBindings.Add(new Binding("Text", ds, "students.name"));
con.Close();
}
现在我想在asp.net上使用此代码.但是在asp.net上不支持"label1.DataBindings".
我的问题是:我想在ASP.net上的label.text 中显示sql中的 Last 字段.
感谢您的回答:缩略图:
Now i want this code on asp.net. But "label1.DataBindings" not suppord on asp.net.
My problem is: I want to show Last field from sql in label.text on ASP.net.
Thanks for your answer:thumbsup:
推荐答案
在ASP.NET中是不可能的.您需要调用DB并从中获取所需的值.然后将该值分配给Label的Text属性
This is not possible in ASP.NET. You need to make a call to DB and get the required value from it. Then assign the value to the Text property of Label
使用以下内容绑定标签
Use the following to bind the label
label1.Text=ds.Tables[0].Rows[0]["name"].ToString();
这篇关于帮助阅读Label中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文