Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ExecuteScalar() question
Message
 
À
25/08/2003 14:14:54
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00823142
Message ID:
00823144
Vues:
16
This message has been marked as the solution to the initial question of the thread.
object oReturnValue = cmd.ExecuteScalar();
if (oReturnValue != null || oReturnValue.ToString() != string.Empty)
{
  companyID = oReturnValue.ToString();
}
else
{
//Other code.
}
>Hi all,
>
>Can I optimze these lines of code to a single line of code? These codes executes ExecuteScalar() twice if there is a result. Assume there is no error.
>
>
>OracleConnection con = new OracleConnection(
>	ConfigurationSettings.AppSettings["cnQuo.ConnectionString"]);
>OracleCommand cmd = new OracleCommand(
>	"SELECT CompanyID FROM Quo.Company " +
>	"WHERE CompanyName = '" + txtCompanyName.Text.Trim() + "'", con);
>string companyID;
>con.Open();
>if (cmd.ExecuteScalar() == null) {companyID = string.Empty;}
>else {companyID = cmd.ExecuteScalar().ToString();}
>
- Jayesh
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform