在Gridview的单元格中计算值(asp.net) [英] Count value in Cells of Gridview (asp.net)
本文介绍了在Gridview的单元格中计算值(asp.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好程序员,
我有网络代码:
Hi programmer,
I have code for web:
Private Sub CountHoNgheo()
Try
Dim HoN As Integer = 0
For i As Integer = 0 To dgInput.Rows.Count - 1
If dgInput.Rows(i).Cells(6).Text Like "ABC" Then
HoN = HoN + 1
End If
Next
lblNgheo1.Text = HoN.ToString
Catch ex As Exception
lblMessage.Text = ex.ToString
End Try
End Sub
结果为0.(实际上,结果= 2)
单元索引号是正确的。
此外,在应用程序中使用此代码,应用于DataGridView,结果是正确的。
最好的谢谢
The result is 0. (In fact, result = 2)
Cell index number is correct.
Also, with this code in application, applied to DataGridView, the result is correct.
Best thank
推荐答案
好的,我已经完成了。这是我的代码:
Ok, I've done it. This is my code:
Private Sub CountHoNgheo()
Try
Connect()
Dim ds As New DataSet
ds.Clear()
Dim da As New OleDbDataAdapter("SELECT * from tblKH WHERE(((tbl.A) = 'ABC'))", cn)
lblNgheo1.Text = da.Fill(ds, "tbl").ToString
Catch ex As Exception
lblMessage.Text = ex.ToString
End Try
End Sub
感谢您的建议!
Thank for your suggestion!
使用SQL查询而不是在gridview上使用for-loop,如下所示: br />
Instead of using for - loop on the gridview, use SQL query as is shown below:
SELECT COUNT(*)
FROM TableName
WHERE FieldName Like "ABC*"
如需了解更多信息,请参阅:
演练:使用ADO.NET编辑Access数据库 [ ^ ]
ADO.NET代码示例 [ ^ ]
为初学者使用ADO.NET [ ^ ]
For further information, please see:
Walkthrough: Editing an Access Database with ADO.NET[^]
ADO.NET Code Examples[^]
Using ADO.NET for beginners[^]
这篇关于在Gridview的单元格中计算值(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文