日期:2014-05-19  浏览次数:20810 次

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