使用C#在asp.net中的sql中显示表中的所有数据 [英] display all data in a table from sql in asp.net using C#
问题描述
我只是用c#学习asp.net.用PHP的知识很少,我认为我能够做些事情,但是在显示数据库中的记录时遇到了问题.
i'm just learning asp.net with c#. with the little knowledge of php, i think i'm able to do somethings but i'm having problem displaying records from my database.
我有一个称为资源的表,我想做的就是输出表中的所有数据. 这是我想在php中用c#编写的输出...
i have a table called resources, what i want to do is output all the data in the table. this is the output i want to write in c# in php...
<?php
while($row = mysql_fetch_object($tablename))
{
echo "<tr><td>$row->image</td><td><a href='#'>download link</a></td><a href='http://'".$row->url."'>'".$row->url."'</a></tr>";
}
?>
基本上我没有使用php的问题,但是我希望此代码的输出将在C#中为我提供相同的功能(带有图像,下载链接和表中的url).请帮忙,...
basically i don't have problem with the php but i want the output this code will give me same in C#(with image, download link, and url in a table). Please help,...
我在C#中有此代码,可在标签控件中输出数据
i have this code in c# to output data in a label control
var cmd = new MySqlCommand("SELECT * FROM resources");
Knct dal = new Knct();
MySqlDataReader dr = dal.DatareaderMethod(cmd, Knct.executemethods.ExecuteReader);
while (dr.Read())
{
label1.Text = dr[2].ToString();
}
while循环不起作用,它仅显示一个值.我如何使它显示数据库中的所有记录,以及我可以使用哪个asp控件输出记录,并在表输出中创建url链接.
the while loop is not working, it only display one value. how do i make this a display all records in the database and which asp control can i use to output the records and also make a url link in the table output.
推荐答案
像这样使用
<asp:GridView ID="grdPivot" runat="server" AutoGenerateColumns="True">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MySql %>" ProviderName="<%$ ConnectionStrings:MySql.ProviderName %>" SelectCommand="SELECT * FROM resources"></asp:SqlDataSource>
这是将数据绑定到gridview或任何其他数据控件的最简单方法.
This is the simplest way to bind data to a gridview or any other data control.
这篇关于使用C#在asp.net中的sql中显示表中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!