Posted By

nimblebits on 11/28/12


Tagged

basic sql method count function VBNet visual OleDB Scalar


Versions (?)

VB.NET Method Perform Scalar


 / Published in: VB.NET
 

This is a method that can be used to take a connection string and a valid oledb command and perform a scalar. This returns an Integer/Int32 value.

  1. Private conn As OleDbConnection = New OleDbConnection()
  2. 'Private conn As New OleDbConnection
  3.  
  4. Public Function doScalar(ByVal connString As String, ByVal command As OleDb.OleDbCommand) As Int32
  5. Dim value As Int32 = 0
  6.  
  7. Try
  8. conn.ConnectionString = connString
  9. command.Connection = conn
  10. conn.Open()
  11. value = command.ExecuteScalar()
  12. Catch ex As Exception
  13. MsgBox("An Error Was Encountered:" & ex.Message, MsgBoxStyle.Information, "Database Error")
  14. Return Nothing
  15. Finally
  16. conn.Close()
  17. command.Dispose()
  18. End Try
  19.  
  20. Return value
  21. End Function

Report this snippet  

You need to login to post a comment.