【发布时间】:2023-03-19 08:58:01
【问题描述】:
我的代码遇到了一个可怕的问题。当我执行 DataBind 方法时,页面加载并加载,几乎 5 分钟后 GridView 被填充。这不是 SQL 查询问题!
我使用 Visual Studio 调试器进行了测试,代码在 DataBind() 上停止
Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) /* This is not the correct code but at the end, the result will be same as below */ Dim feedback As String = "positive" Dim date As String = "2013" bindDataShowDetails(feedback, date) // <----- I call this method ( below ) End Sub
Protected Sub bindDataShowDetails(ByVal feedback As String, ByVal Data As String())
feedbackGlobal = feedback
Dim strSql As String = ""
strSql = " select "
strSql += " feedback, zendesk_ticket_id,feedback_text as Comment, date_ins as Ticket_date, date_feedback as Feedback_date, comment_review, review_status "
strSql += " from feedbacks_support "
strSql += " where "
strSql += " feedback = '" & feedback & "'" // <---- 'positive'
strSql += " and YEAR(date_feedback) = " & Date // <---- '2013'
Dim myreader As SqlDataReader = admin2.ExecReader(strSql) // <--- Class 'admin2' calls the method (ExecReader) thats executes the SQL query and return the result.
GridView1.DataSource = myreader
GridView1.DataBind() <----------- Problem is here!!!
Me.ModalPopupExtender1.Show()
End Sub
我在 SQL Server 中直接运行了 SQL 查询,它运行良好!
我真的不知道怎么了! 非常感谢您的支持!
【问题讨论】:
-
查询返回多少条记录?
-
使用参数来避免 SQL 注入,即使是很小的事情。我会避免使用“日期”这个词作为变量。参数虽然是“数据”,而不是“日期”。
-
@YuriyGalanter 2445 条记录
-
@RodrigoAbib 一次显示超过 2000 条记录并不是一个好主意,分页可能是更好的选择。同时查看将数据检索到 DataTable 是否会产生更好的性能(并且您可以缓存该数据表以进行分页)
标签: vb.net performance gridview data-binding