Issuing a Command that Returns Only One Value

Issue a command that returns a single complete result set.

  1. Declare and initialize an AseConnection object:

    For C#:

    AseConnection conn = new AseConnection(
       "Data Source='mango';" +
       "Port=5000;" +
       "UID='sa';" +
       "PWD='';" +
       "Database='pubs2';" );

    For Visual Basic .NET:

    Dim conn As New AseConnection( _
       "Data Source='mango';" + _ 
       "Port=5000;" + _
       "UID='sa';" + _
       "PWD='';" + _
       "Database='pubs2';")

    where “mango” is the name of the database server.

  2. Open the connection:

    For C#:

    conn.Open();

    For Visual Basic .NET:

    conn.Open()
  3. Add an AseCommand object to define and execute a SQL statement:

    For C#:

    AseCommand cmd = new AseCommand(
      "select count(*) from authors where state = 'CA'",
      conn );

    For Visual Basic .NET:

    Dim cmd As New AseCommand(
     "select count(*) from authors where state = 'CA'"_,
     conn );
  4. Call the ExecuteScalar method to return the object containing the value:

    For C#:

    int count = (int) cmd.ExecuteScalar();

    For Visual Basic .NET:

    Dim count As Integer = cmd.ExecuteScalar()
  5. Close the AseConnection object:

    For C#:

    conn.Close();

    For Visual Basic .NET:

    conn.Close()

When using the AseDataReader, there are several Get methods available that you can use to return the results in the desired datatype.

Related concepts
AseDataReader Class