Handling ExecuteScalar() when no results are returned

后端 未结 22 1080
猫巷女王i
猫巷女王i 2020-11-27 05:47

I am using the following SQL query and the ExecuteScalar() method to fetch data from an Oracle database:

sql = \"select username from usermst wh         


        
22条回答
  •  一生所求
    2020-11-27 06:06

    this could help .. example::

    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    class ExecuteScalar
    {
      public static void Main()
      {
        SqlConnection mySqlConnection =new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");
        SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
        mySqlCommand.CommandText ="SELECT COUNT(*) FROM Employee";
        mySqlConnection.Open();
    
        int returnValue = (int) mySqlCommand.ExecuteScalar();
        Console.WriteLine("mySqlCommand.ExecuteScalar() = " + returnValue);
    
        mySqlConnection.Close();
      }
    }
    

    from this here

提交回复
热议问题