MyException - 我的异常网
当前位置:我的异常网» C# » oledb联接sql server2000出错?

oledb联接sql server2000出错?

www.MyException.Cn  网友分享于:2013-12-21  浏览:5次
oledb连接sql server2000出错?急!!!!!!!!!
string   Sql   =   null;
Conn.Open();
UserName   =   ChangeHope_fc.newstr(this.username.Value.ToString());
Pwd   =   FormsAuthentication.HashPasswordForStoringInConfigFile(ChangeHope_fc.newstr(this.password.Value.ToString()),   "md5 ");
Sql   =   "select   *   from   YX_Manage   where   YX_AdminUser=@YX_AdminUser   and   YX_Pwd=@YX_Pwd   and   YX_Stat=0 ";
OleDbCommand   Comm   =   new   OleDbCommand(Sql,   Conn);
Comm.Parameters.Add(new   OleDbParameter( "@YX_AdminUser ",   OleDbType.VarChar,   8));
Comm.Parameters[ "@YX_AdminUser "].Value   =   UserName;
Comm.Parameters.Add(new   OleDbParameter( "@YX_Pwd ",   OleDbType.VarChar,   50));
Comm.Parameters[ "@YX_Pwd "].Value   =   Pwd;
int   Count   =   Convert.ToInt32(Comm.ExecuteScalar());

OleDbCommand   Comm   =   new   OleDbCommand(Sql,   Conn);
OleDbDataReader   dr   =   Comm.ExecuteReader();

这样写会出现必须声明@YX_AdminUser的错误(注:跑access不会错)
但是直接写sql执行跑sql   server2000又不错
Sql   =   "select   *   from   YX_Manage   where   YX_AdminUser= ' "   +   UserName   +   " '   and   YX_Pwd= ' "   +   Pwd   +   " '   and   YX_Stat=0 ";
这到底是为什么   高手指点


------解决方案--------------------
OleDbCommand就是为了跑access,

跑sql用sqlcommand

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有