public static bool AdminLogin(Admin ad)
    {
        using (DataBase db = new DataBase())
        {
        SqlCommand com = new SqlCommand();
        com.Connection = db.Connection;
        com.CommandType = CommandType.StoredProcedure;
        com.CommandText = "dbo.hs_AdminLogin";
        com.Parameters.Add("@aName",SqlDbType.VarChar,100).Value = ad.aName;
        com.Parameters.Add("@aPwd", SqlDbType.VarChar, 100).Value = ad.aPwd;
        int count = Convert.ToInt32(com.ExecuteScalar());
        return count > 0 ? true : false;
        }
    }
报这个错:
ExecuteScalar: Connection property has not been initialized. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteScalar: Connection property has not been initialized.Source Error: 
Line 92:         com.Parameters.Add("@aName",SqlDbType.VarChar,100).Value = ad.aName;
Line 93:         com.Parameters.Add("@aPwd", SqlDbType.VarChar, 100).Value = ad.aPwd;
Line 94:         int count = Convert.ToInt32(com.ExecuteScalar());
Line 95:         return count > 0 ? true : false;
Line 96:         }
 

解决方案 »

  1.   

    ExecuteScalar: Connection property has not been initialized. 
    说的很清楚啊是不是没设置connectionString?
      

  2.   

    肯定错了,你的存储过程只传值,并没有返回值,那怎么又能够帮你查询到count呢?
      

  3.   

    你没有吧SqlConnection对象Open吧!
      

  4.   

    1楼的,他已经用了连接类,所以不需要connectionString
      

  5.   

    看看db.Connection 在哪里初始化的
      

  6.   


     int count = Convert.ToInt32(com.ExecuteScalar()); 
    ------
    int count=int.parse(com.ExecuteScalar().ToString());
      

  7.   


    你设置传回个count,肯定不会报错,你不要这样写,感觉写的很乱
      

  8.   

    断点调试一下啊
    看看Sqlconnection对象OPEN没有啊