如何检索要标记的特定列数据 [英] how to retrieve particular column data to label

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

问题描述

如何从ssql检索特定列数据以将标签标记为asp.net标签
感谢adv并感谢我在这个论坛上的所有朋友..很高兴能以这种形式获得我所学到的大力支持,并从中学到了很多东西

how to retrieve particular column data to label from ssql to asp.net label
thanks in adv and happy ugadi to all my friends at this forum.. happy to be in this form for the great support i learnt and learing things

推荐答案

执行您的查询:选择<列名>来自< table-name> ;;

现在,在最后一行时读取数据行read()并将字符串追加到stringbuilder中.

现在label1.Text = stringbuilder.ToString();
Execute your query:select <column-name> from <table-name>;

now, data-row read() while last-row and append the string in stringbuilder .

now label1.Text=stringbuilder.ToString();


像这样尝试:

Hi, try like this:

protected void btnTest_Click(object sender, EventArgs e)
   {

String ConnStr = "Data Source=ServerName;Initial Catalog=DBNamae;User ID=UserName;Password='password';";
        String SQL = "SELECT ID, FirstName FROM Employee "
           + "WHERE ID IS NOT NULL";
        SqlDataAdapter TitlesAdpt = new SqlDataAdapter(SQL, ConnStr);
        DataSet Titles = new DataSet();
        // No need to open or close the connection
        //   since the SqlDataAdapter will do this automatically.
        TitlesAdpt.Fill(Titles);
YourLabel.Text=Titles.Table[0].Rows[0]["FirstName"].ToString();
}



这里假设表是Employee,名字将显示在您的标签中.
祝您好运



Here assuming that the table is Employee and the FirstName will show in your lable.
Best of luck


SELECT <column_name> FROM <table_name></table_name></column_name>



现在,您可以在前面进行操作了....
连接到数据服务器..



Now in the front part you can do....
connect to data server..

SqlConnection Con = new SqlConnection(Connstr);
string str = "SELECT <column_name> FROM <table_name> <where condition="">";
SqlCommand cmd = SqlCommand(str, Con);

SqlDataAdapter Adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();

Adapter.Fill(dt);

lbl.text = dt.Rows[0].ItemArray[0].ToString();
</where></table_name></column_name>



现在,您可以在标签中找到选定的列数据....



Now you can find selected column data in the label....


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

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