title: vb.net count distinct row in sql and store it in INT variable
body: <p>i need to count the distinct row in sql database
  and after that the result will be stored in Int variable</p>
  
  <p>for example
  count the distinct row(SalesID) in tblSales(table)
  and store it in NUM(int variable) .</p>
  
  <p>TIA :)</p>
  
  <pre><code>    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
  </code></pre>