Método Command.ExecuteScalar

Use the ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a database. This requires less code than using the ExecuteReader method, and then performing the operations necessary to generate the single value from the data returned by a DataReader.

A typical ExecuteScalar query can be formatted as in the following VB example:

conn = New Data.SqlClient.SqlConnection(strConn)
cmd = New Data.SqlClient.SqlCommand(sSQL, conn)
Dim ValorDB as Integer = cmd.ExecuteScalar()

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *