计算数据集中有多少行,然后在文本框中显示为文本?

发布于 2024-12-12 01:53:30 字数 178 浏览 0 评论 0原文

如何计算数据集返回的行数,然后将总行数显示为 textbox.text 和只读,以便用户只能看到它们而不能更改它们?

到目前为止,我有这个,但它没有返回一个数字,并说它找不到表 0:

tbRecordsFound.Text = ds.Tables(0).Rows.Count

How can I count how many rows are returned by a dataset and then show the total number of rows as textbox.text and read-only so that the user can only see them but not change them?

so far I have this but it dosent return a number and says it cant find table 0:

tbRecordsFound.Text = ds.Tables(0).Rows.Count

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

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

发布评论

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

评论(3

绿萝 2024-12-19 01:53:30

尝试这样的事情:

tbRecordsFound.Text = ds.Tables.Cast<DataTable>().Sum(x => x.Rows.Count).ToString()

你也可以这样做:

Dim recordCount as Integer = 0;
For Each table as Datatable in ds.Tables
    recordCount += table.Rows.Count
tbRecordsFound.Text = recordCount.ToString()

Try something like this:

tbRecordsFound.Text = ds.Tables.Cast<DataTable>().Sum(x => x.Rows.Count).ToString()

You can also do it like this:

Dim recordCount as Integer = 0;
For Each table as Datatable in ds.Tables
    recordCount += table.Rows.Count
tbRecordsFound.Text = recordCount.ToString()
清引 2024-12-19 01:53:30
tbRecordsFound.Text = ds.Tables(0).Rows.Count

上面的代码可以工作,但是您需要为表提供一个标识符,例如:

tbRecordsFound.Text = ds.Tables("TableName").Rows.Count

这可以通过创建 DataAdapter 并使用“Fill”函数为表提供名称来完成。下面是一个示例,其中“da”代表 DataAdapter:

da.Fill(ds, "TableName")
tbRecordsFound.Text = ds.Tables(0).Rows.Count

The above code will work, however you need to give the table an identifier, such as:

tbRecordsFound.Text = ds.Tables("TableName").Rows.Count

This can be done via creating a DataAdapter and using the "Fill" function to give the table a name. Here is an example where "da" represents the DataAdapter:

da.Fill(ds, "TableName")
滥情稳全场 2024-12-19 01:53:30
For i As Integer = 0 To yourdatagridviewName.Rows.Count() - 1 Step +1
        i = +i
        TextBox2.Text = i 
    Next
For i As Integer = 0 To yourdatagridviewName.Rows.Count() - 1 Step +1
        i = +i
        TextBox2.Text = i 
    Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文