如何使用VB.NET从数据库中计算记录?

时间:2021-12-03 01:40:32

I have the code below:

我有以下代码:

 Dim ds As New DataSet
 Dim sda As System.Data.SqlClient.SqlDataAdapter
 Dim sSQL As String
 Dim strCon As String

 sSQL = " .... MY QUERY HERE .... "

 strCon = appBase.dbConnString

 sda = New System.Data.SqlClient.SqlDataAdapter(sSQL, strCon)
 sda.Fill(ds, "MY TABLE FROM DB")


 dgRecordsContent.DataSource = ds.Tables("MY TABLE FROM DB")
 dgRecordsContent.DataBind()

 dgRecordsContent.Visible = True

 dbConn.Close()

How can I programatically count the number of rows from the datagrid that I'm showing the values in?

我如何以编程方式计算数据网格中我显示值的行数?

3 个解决方案

#1


1  

Provided that the DataTable being filled doesn't already contain any rows, you can get the count using:

如果正在填充的DataTable尚未包含任何行,则可以使用以下命令获取计数:

int count = sda.Fill(ds, "MY TABLE FROM DB")

Otherwise you can access the rows in the DataTable using:

否则,您可以使用以下方法访问DataTable中的行:

int count = ds.Tables("MY TABLE FROM DB").Rows.Count

#2


0  

you can use ds.Tables[0].Rows.Count

你可以使用ds.Tables [0] .Rows.Count

#3


0  

 Dim ds As New DataSet
 Dim sda As System.Data.SqlClient.SqlDataAdapter
 Dim sSQL As String
 Dim strCon As String

 sSQL = " .... MY QUERY HERE .... "

 strCon = appBase.dbConnString

 sda = New System.Data.SqlClient.SqlDataAdapter(sSQL, strCon)
 Dim num_rows=sda.Fill(ds, "MY TABLE FROM DB")

 MessageBox.Show(num_rows.ToString())  

 dgRecordsContent.DataSource = ds.Tables("MY TABLE FROM DB")
 dgRecordsContent.DataBind()

 dgRecordsContent.Visible = True

 dbConn.Close()  

Please Check This Edit @Emi

请检查此编辑@Emi

#1


1  

Provided that the DataTable being filled doesn't already contain any rows, you can get the count using:

如果正在填充的DataTable尚未包含任何行,则可以使用以下命令获取计数:

int count = sda.Fill(ds, "MY TABLE FROM DB")

Otherwise you can access the rows in the DataTable using:

否则,您可以使用以下方法访问DataTable中的行:

int count = ds.Tables("MY TABLE FROM DB").Rows.Count

#2


0  

you can use ds.Tables[0].Rows.Count

你可以使用ds.Tables [0] .Rows.Count

#3


0  

 Dim ds As New DataSet
 Dim sda As System.Data.SqlClient.SqlDataAdapter
 Dim sSQL As String
 Dim strCon As String

 sSQL = " .... MY QUERY HERE .... "

 strCon = appBase.dbConnString

 sda = New System.Data.SqlClient.SqlDataAdapter(sSQL, strCon)
 Dim num_rows=sda.Fill(ds, "MY TABLE FROM DB")

 MessageBox.Show(num_rows.ToString())  

 dgRecordsContent.DataSource = ds.Tables("MY TABLE FROM DB")
 dgRecordsContent.DataBind()

 dgRecordsContent.Visible = True

 dbConn.Close()  

Please Check This Edit @Emi

请检查此编辑@Emi