SqlClient ExecuteScalar Method (String)Nemiro.Data.dll
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

Namespace: Nemiro.Data.Sql
Assembly: Nemiro.Data (in Nemiro.Data.dll) Version: (

public Object ExecuteScalar(
	string sql


Type: System String

Return Value

Type: Object

The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty. Returns a maximum of 2033 characters.


SqlExceptionThe exception that is thrown when SQL Server returns a warning or error.
ValueForIdentityExceptionAn exception occurs if the property of primary key has not flag the Identity and field is autoincrement.
StringOrBinaryDataWouldBeTruncatedExceptionAn exception occurs if some of the fields of the table are added values ​​that exceed the allowable size of a table field.

using (SqlClient client = new SqlClient())
  object result = client.ExecuteScalar("SELECT nickname FROM users WHERE id_users = 1");
  Console.WriteLine("User nickname: {0}", result);
See Also