从sql检索要标记的值 [英] Retrieve value to label from sql

查看:115
本文介绍了从sql检索要标记的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql中有5条记录,我在数据库中有一个id和名称

如果我想在运行时在标签中获取这些名称和ID.

任何想法...

i have 5 records in sql i have an id and name in the database

if i want to get those name and id in a label at run time..

Any Idea...

推荐答案

来自您的琐碎问题之列令人叹为观止.为什么不买书看书呢?告诉我有人不为您生成的代码付款吗?

标签具有Text属性.设置它,使用您从数据库中获得的数据.
The stream of trivial questions from you is breathtaking. Why not buy a book and read it ? Tell me someone is not paying for the code you''re producing ?

The label has a Text property. Set it, using data you get from the DB.


这里是问题朋友的答案.


受保护的void Button1_Click(对象发送者,EventArgs e)
{
SqlConnection con =新的SqlConnection("server = sss; database = xyz; integrated security = true");
con.Open();
SqlCommand cmd =新的SqlCommand(从实验室选择*,其中id =" + TextBox1.Text,con);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
Label1.Text = Convert.ToString(dr [0]);
Label2.Text = Convert.ToString(dr [1]);

}
}
Here is answer for the Question Friends.. Atlast i go this...



protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=sss;database=xyz;integrated security=true");
con.Open();
SqlCommand cmd = new SqlCommand(" select * from lab where id=" + TextBox1.Text, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = Convert.ToString(dr[0]);
Label2.Text = Convert.ToString(dr[1]);

}
}


protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=sss;database=xyz;integrated security=true");
con.Open();
SqlCommand cmd = new SqlCommand(" select * from lab where id=" + TextBox1.Text, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = Convert.ToString(dr[0]);
Label2.Text = Convert.ToString(dr[1]);

}
}



是的,这将起作用.但是,再一次,请告诉我,没有人为此付出代价,这种糟糕,设计欠佳且难以阅读的代码付了钱吗?除了所有其他问题之外,您还意识到,如果将此代码投入生产,您的用户可以在自己希望的任何时间擦除自己的数据库,可能创建用户等,而这一切都在您的控制范围之外?

如果您正在学习,那很好.但是,在那种情况下,人们希望您会选择自己可以达到的任务,而不是花数周的时间反复询问如何做同样的事情?如果您选择以适当的速度学习,那么您将每天学习,并且不会为完成相同任务而费时数周.



Yes, this will work. However, again, PLEASE tell me that no-one is paying for this awful, poorly designed and hard to read code ? Apart from all the other issues that it has, you realise that if you put this code into production, your users can erase your database any time they like, probably create users, etc, all outside your control ?

If you''re learning, that''s fine. But, in that case, one would hope that you''d choose tasks that are within your reach, instead of spending weeks asking how to do the same things, over and over ? If you choose to learn at a proper pace, you will learn daily, and not struggle for weeks with the same task.


这篇关于从sql检索要标记的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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