如何在ASP.NET网页中实现数据库中的动态行抽取? [英] How to implement dynamic row pumping, in an ASP.NET webpage, from database?

查看:112
本文介绍了如何在ASP.NET网页中实现数据库中的动态行抽取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在为我的网站开发一个SEARCH页面,我希望从数据库中获取结果。

现在显然,只有列数是固定的,而不是基于用户提供的搜索参数本质上是动态的行数。我知道,答案必须相当简单,但我是c#的新手,这就是为什么我想知道实现这个目标的方法。



在给出答案之前,请考虑所有数据库连接都已完成,结果存在于DataTable dt中,它们通过DataAdapter da引入。现在,

我想要该部分的代码:





if(dt.Rows.Count> 0)

{

//如何表示获取的数据?

}





提前谢谢。

Hello everyone,

I am developing a SEARCH page for my website, where I want results fetched from the database.
Now obviously only the number of columns is fixed, and not the number of rows, which is dynamic in nature based on the search parameters, provided by the user. I know, the answer must be fairly simple but I'm new to c#, that is why I want to know the approach to achieve this.

Before giving the answer, kindly consider that all the database connections have been done, and results are residing in a DataTable dt, where they were brought through a DataAdapter da. Now,
I want the code for the section:


if(dt.Rows.Count>0)
{
//How to represent the fetched data??
}


Thanks in advance.

推荐答案

确实解决方案非常简单......我所要做的就是将网格视图的源设置为已获取和存储数据的数据表dt。

代码: -



if(dt.Rows.Count> 0)

{

grid_view.DataSource = dt;

grid_view.DataBind();



}
Well the solution was really simple indeed... All I had to do was to set the source of the Grid view as the data table dt where the data was already fetched and stored.
Code:-

if (dt.Rows.Count > 0)
{
grid_view.DataSource = dt;
grid_view.DataBind();

}


这篇关于如何在ASP.NET网页中实现数据库中的动态行抽取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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