报错!高手指点!!!!谢谢了!!!!

bingwangzi 2008-07-11 08:00:48
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: }

...全文
100 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
SANSWATER 2008-07-11
  • 打赏
  • 举报
回复
连接对象出错了,
ljqingas 2008-07-11
  • 打赏
  • 举报
回复
断点调试一下啊
看看Sqlconnection对象OPEN没有啊

mengjun5200 2008-07-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mengjun5200 的回复:]
肯定错了,你的存储过程只传值,并没有返回值,那怎么又能够帮你查询到count呢?
[/Quote]

你设置传回个count,肯定不会报错,你不要这样写,感觉写的很乱
sxmonsy 2008-07-11
  • 打赏
  • 举报
回复
还有你的存储过程是怎么写的,有没有返回值?
sxmonsy 2008-07-11
  • 打赏
  • 举报
回复

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



xxoo2007 2008-07-11
  • 打赏
  • 举报
回复
看看db.Connection 在哪里初始化的
yagebu1983 2008-07-11
  • 打赏
  • 举报
回复
你设置连接字符串了吗???
mengjun5200 2008-07-11
  • 打赏
  • 举报
回复
1楼的,他已经用了连接类,所以不需要connectionString
sheng9hhd 2008-07-11
  • 打赏
  • 举报
回复
你没有吧SqlConnection对象Open吧!
mengjun5200 2008-07-11
  • 打赏
  • 举报
回复
肯定错了,你的存储过程只传值,并没有返回值,那怎么又能够帮你查询到count呢?
sharpblade 2008-07-11
  • 打赏
  • 举报
回复
ExecuteScalar: Connection property has not been initialized.
说的很清楚啊

是不是没设置connectionString?

61,817

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧