VB.NET Method Perform Scalar

Submitted by:Jhon Smith

Date added:15 July, 2013

Category: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.

Tags: scalar

Code Snippet:

    Private conn As OleDbConnection = New OleDbConnection()
'Private conn As New OleDbConnection

Public Function doScalar(ByVal connString As String, ByVal command As OleDb.OleDbCommand) As Int32
Dim value As Int32 = 0

Try
conn.ConnectionString = connString
command.Connection = conn
conn.Open()
value = command.ExecuteScalar()
Catch ex As Exception
MsgBox("An Error Was Encountered:" & ex.Message, MsgBoxStyle.Information, "Database Error")
Return Nothing
Finally
conn.Close()
command.Dispose()
End Try

Return value
End Function
 
 

Comments