command class : Scalar() method

Description

Executes the SQL statement.

Syntax

instance.Scalar()

Arguments

None.

Return value

ClassDescription
stringThe first column of the first row of the result set.

Sample code

1:

connection cnn = new connection("Data Source=c:\somedirectory\somedatabase.sqlite3;Version=3;");

2:

cnn.Open();

3:

// It makes sure of existence of the "sometable".

4:

command cmm = new command("select count(*) from sqlite_master where type='table' and name='sometable';", cnn);

5:

// If it exists, return 1 in string. Otherwise, return 0 in string.

6:

string numStr = cmm.Scalar();

7:

cmm.Release();

8:

cnn.Close();

9:

cnn.Release();

Notes

Please notice that the return value is string.

If the result is a number, the number will be returned as a string. For example, 1is '1', 1.05 is '1.05'.

If the result is a string, the string will be enclosed in double quotes and returned. For example, 'Returned string' is '"Returned string"'.

If the result is null or cannot be evaluated, the string, 'null', is returned.

Links for reference

None.

Copyright © Cooker All rights reserved.