Executes the specified SqlCommand, 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.SqlAssembly: Nemiro.Data (in Nemiro.Data.dll) Version: 2.11.4.126 (2.11.4.126)
Syntax
Parameters
- cmd
- Type: System.Data.SqlClient SqlCommand
Return Value
Type: ObjectThe 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.
Exceptions
Exception | Condition |
---|---|
SqlException | The exception that is thrown when SQL Server returns a warning or error. |
ValueForIdentityException | An exception occurs if the property of primary key has not flag the Identity and field is autoincrement. |
StringOrBinaryDataWouldBeTruncatedException | An exception occurs if some of the fields of the table are added values that exceed the allowable size of a table field. |
Examples
using (SqlClient client = new SqlClient()) { SqlCommand cmd = new SqlCommand("SELECT nickname FROM users WHERE id_users = @id_users"); cmd.Parameters.Add("@id_users", SqlDbType.Int).Value = 1024; Console.WriteLine("User nickname: {0}", client.ExecuteScalar(cmd)); }
See Also