如何计算数据集返回的行数,然后以textbox.text和只读方式显示总行数,以便用户只能看到它们但不能更改它们?
到目前为止,我有这个,但它会返回一个数字并说它无法找到表0:
tbRecordsFound.Text = ds.Tables(0).Rows.Count
答案 0 :(得分:2)
尝试这样的事情:
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()
答案 1 :(得分:1)
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/theo82"
},
"keywords": [
"test"
],
"author": "Theo Tziomakas",
"license": "ISC",
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
}
}
上面的代码可以使用,但是您需要为表提供一个标识符,例如:
tbRecordsFound.Text = ds.Tables(0).Rows.Count
这可以通过创建DataAdapter并使用&#34; Fill&#34;来完成。函数给表一个名字。这是一个例子,其中&#34; da&#34;代表DataAdapter:
tbRecordsFound.Text = ds.Tables("TableName").Rows.Count
答案 2 :(得分:0)
For i As Integer = 0 To yourdatagridviewName.Rows.Count() - 1 Step +1
i = +i
TextBox2.Text = i
Next