如何将数据列表传递给视图

发布于 2024-09-18 14:01:40 字数 1639 浏览 4 评论 0原文

实际上,我想在视图上生成申请人列表(超过 1000 个),因为我正在使用 sql 数据读取器并生成列表并传递给视图,但需要很长时间(4 到 5 秒)才能在视图上显示记录超过500条是很正常的。

{

public static ApplicantsList GetListSend(字符串类别, 字符串 subDiv) { 字符串 os = "N"; if(类别==“SCOS”) 操作系统=“Y”; 申请人应用程序;//申请人类别包含姓名、地址、电话等//// ApplicantsList AppList = new ApplicantsList();//ApplicantLst类列表类型// 字符串 sqlcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); SqlConnection con = new SqlConnection(sqlcon); con.Open(); string SqlQuery = "SELECT [idno], [ApplicantName], [Address], [Status], Convert(varchar(10), DateOfApplication,103) as DateOfApplication FROM [SCOBC] where (status = 'Pending With Dealing Assistant' and Category ='" + 类别 + "') 和 SubDiv ='" + subDiv + "' 和 os ='" + os + "' 按 idno 排序"; SqlCommand cmd = new SqlCommand(SqlQuery, con); SqlDataReader sdr = null; sdr = cmd.ExecuteReader(); if (sdr.HasRows) { while (sdr.Read()) { 应用程序=新申请人(); App.IdNo = sdr["idno"].ToString(); App.Name = sdr["ApplicantName"].ToString(); App.Address = sdr["地址"].ToString(); App.Status = sdr["Status"].ToString(); App.DateOfApp = sdr["DateOfApplication"].ToString(); 应用程序列表.添加(应用程序);

            }
            sdr.Close();
            con.Close();
        }
        return AppList;
    }

}

Actually i want to generate a list of applicants (more than 1000) on a view for that i am using sql data reader and genrting a List and passing to Views but it is taking big time(4 to 5 second) to show on View when records are more than 500 is this normal .

{

public static ApplicantsList GetListSend(string category, string subDiv)
{
string os = "N";
if (category == "SCOS")
os = "Y";
Applicant App;//Applicant Class Contains Name,Address,Phone etc////
ApplicantsList AppList = new ApplicantsList();//ApplicantLst Class List type//
string sqlcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
SqlConnection con = new SqlConnection(sqlcon);
con.Open();
string SqlQuery = "SELECT [idno], [ApplicantName], [Address], [Status], convert(varchar(10), DateOfApplication,103) as DateOfApplication FROM [SCOBC] where (status = 'Pending With Dealing Assistant' and category='" + category + "') and SubDiv ='" + subDiv + "' and os ='" + os + "' order by idno";
SqlCommand cmd = new SqlCommand(SqlQuery, con);
SqlDataReader sdr = null;
sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
App = new Applicant();
App.IdNo = sdr["idno"].ToString();
App.Name = sdr["ApplicantName"].ToString();
App.Address = sdr["Address"].ToString();
App.Status = sdr["Status"].ToString();
App.DateOfApp = sdr["DateOfApplication"].ToString();
AppList.Add(App);

            }
            sdr.Close();
            con.Close();
        }
        return AppList;
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

差↓一点笑了 2024-09-25 14:01:40

我不知道你的数据库调用需要 4-5 秒是否正常,但不正常的是在单个视图上显示 1000 个项目的列表而不实现分页。

当您实现分页时,不仅可以使页面更小并且更易于用户阅读,而且还可以大大提高性能,因为您将只获取需要的内容。当然,为了使其有效,分页必须在 SQL Server 上完成。

I don't know if it is normal that your database call takes 4-5s but what is not normal is showing a list of 1000 items on a single view without implementing paging.

When you implement paging not only you will make your page smaller and easier to read from the users but will greatly improve performance as you will be fetching only what's needed. Of course in order for this to be effective the paging must be done on the SQL Server.

献世佛 2024-09-25 14:01:40

包含如此多数据的页面需要很长时间才能呈现的情况并不罕见。下一步是确定页面生命周期的哪一部分占用了这么多时间。它可能是 SQL 调用、HTML 呈现或其他问题,但您确实需要限制问题的范围,以有效地计划如何修复它。我见过 SQL 查询速度非常快,但由于数据量巨大,HTML 页面太大,以至于 Web 浏览器需要很长时间才能呈现它。

It is not unusual to see a page with so much data take a long time to render. The next step is to determine which part of the pages life cycle is taking up so much time. It could be the SQL call, the rendering of the HTML, or something else but you really need to limit the scope of the problem to effectively plan how you are going to fix it. I have seen it where the SQL query is really fast but with tons of data the HTML page is so large that it takes the web browser forever to render it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文