我需要计算 sql 数据库中的不同行,然后结果将存储在 Int 变量中
例如计算 tblSales(table) 中的不同行(SalesID) 并将其存储在 NUM(int variable) 中。
蒂亚:)
Public Function ExecuteQuery(ByVal query As String) As DataTable
Try
Dim cn As New SqlConnection(con)
Dim da As New SqlDataAdapter(query, cn)
Dim cb As New SqlCommandBuilder(da)
Dim dt As New DataTable
da.Fill(dt)
Return dt
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
dim count as string = "select distinct count(SalesID) from tblSales"
ExecuteQuery(count)
dim Num as Integer = Int32.Parse(Val(count))
End Sub