title: how to populate value from database using executescaler using vb.net
body: <p>I have a database in ms access with table name <code>regn</code>.  I want to populate the field name <code>nocount</code> using command text and executescaler.  Here is my code:</p>
  
  <pre><code>Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  dim i as integer
      If cn.State = ConnectionState.Open Then
          cn.Close()
      End If
      cn.Open()
  
      cmd.CommandText = "select nocount from regn where pname='" &amp; PNAMETextBox.Text &amp; "' And fname='" &amp; FNAMETextBox.Text &amp; "' And dob='" &amp; DOBDateTimePicker.Text &amp; "' "
      i = cmd.ExecuteScalar
  
      cn.Close()
  </code></pre>