如何从数据库中获取数据并在标签中显示 [英] How to fetch data from database and show in a label

查看:86
本文介绍了如何从数据库中获取数据并在标签中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我需要一个解决方案



在我的数据库中有各种各样的问题和我把它存储在数据集中,现在当我点击按钮时,问题会在点击按钮时逐个显示在标签上。



有没有任何流程呢请帮忙。







谢谢。

Hello

I need a solution that

in my data base there are various question and I stored it in dataset , now when I will click on the button the question will show in a label one by one when click on button.

Is there any process then please help.



Thanks.

推荐答案

是的,有一个过程。它被称为数据绑定,并且在我所知的每本基本ASP.NET书中都有介绍。
Yes there is a process. Its called databinding and is covered in every basic ASP.NET book I know of.


hi,

更改连接字符串并选择Query作为您的要求。 />

change the connectionstring and select Query as your requirement.
public void FetchData_and_Show_in_Label()
   {
       String ConnStr = "Data Source=ServerName;Initial Catalog=DBNamae;User ID=UserName;Password='password';";
       String SQL = "SELECT QuestionText  FROM Questions";
       SqlDataAdapter Adpt = new SqlDataAdapter(SQL, ConnStr);
       DataSet question = new DataSet();
       Adpt.Fill(question);

       foreach (DataRow dr in question.Tables[0].Rows)
       {
           LblQuestion.Text += question.Tables[0].Rows[0]["QuestionText"].ToString() + "<br />";
       }
   }


echo
"<form method='POST' action=''>";
if(!isset(


这篇关于如何从数据库中获取数据并在标签中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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