What should you conclude and recommend?

You are an enterprise application developer. You create a data access layer for an order processing application.
The data access layer meets the following criteria:

The data access layer contains a GetConnectionString method to retrieve and return the connection string for the database.
The data access layer contains a stored procedure named GetTotalOrderAmount. The stored procedure runs a select query to return only the sum of the OrderAmount column for the active orders. At times, there might be no active orders.

You create the following method to execute the stored procedure and return the total.

public double GetTotalOrderAmount() {
SqlConnection con = new SqlConnection(GetConnectionString()); string sql = GetTotalOrderAmount;
SqlCommand cmd = new SqlCommand(sql,con);
IDataReader rd; con.Open(); rd = cmd.ExecuteReader(); double amt = 0.0;
if (rd.Read()) {
amt = rd.GetDouble(0);
}
rd.Close();
con.Close();
return amt;
}

You need to review the code and recommend modifications to simplify the code and improve performance, if necessary. What should you conclude and recommend?

You are an enterprise application developer. You create a data access layer for an order processing application.
The data access layer meets the following criteria:

The data access layer contains a GetConnectionString method to retrieve and return the connection string for the database.
The data access layer contains a stored procedure named GetTotalOrderAmount. The stored procedure runs a select query to return only the sum of the OrderAmount column for the active orders. At times, there might be no active orders.

You create the following method to execute the stored procedure and return the total.

public double GetTotalOrderAmount() {
SqlConnection con = new SqlConnection(GetConnectionString()); string sql = GetTotalOrderAmount;
SqlCommand cmd = new SqlCommand(sql,con);
IDataReader rd; con.Open(); rd = cmd.ExecuteReader(); double amt = 0.0;
if (rd.Read()) {
amt = rd.GetDouble(0);
}
rd.Close();
con.Close();
return amt;
}

You need to review the code and recommend modifications to simplify the code and improve performance, if necessary. What should you conclude and recommend?

A.
The code does not need to be modified.

B.
The code needs to be modified. You must remove the condition that verifies whether the DataReader objec t returned any rows.

C.
The code needs to be modified. You must use a DataSet object instead of a DataReader object.

D.
The code needs to be modified. You must use the ExecuteScalar method instead of the ExecuteReader method.



Leave a Reply 0

Your email address will not be published. Required fields are marked *