首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

一个关于“System.Data.OleDb.OleDbException: 至少一个参数没有被指定值。”的异常?

2011-12-10 
一个关于“System.Data.OleDb.OleDbException: 至少一个参数没有被指定值。”的错误???StringaccessStringWe

一个关于“System.Data.OleDb.OleDbException: 至少一个参数没有被指定值。”的错误???
String   accessString   =   WebConfigurationManager.ConnectionStrings[ "accessConnectionString "].ConnectionString
                      +   Server.MapPath( "data/msgBoard.mdb ");
                OleDbConnection   accessConn   =   new   OleDbConnection(accessString);
                accessConn.Open();
                string   struser,strpwd;
                struser=Txbname.Text.ToString().Trim();
                strpwd=Txbpwd.Text.ToString().Trim();
  string   sql   =   "select   *   from   admin   where   user= "   +struser   +   "   and   password= "   +   strpwd;
                OleDbCommand   cmd   =   new   OleDbCommand(sql,accessConn);
                OleDbDataReader   dr   =   cmd.ExecuteReader();//   错误所在行         if   (dr.Read())
{
                                        Session[ "identity "]   =   "admin ";      
  Response.Redirect( "admin.aspx ");
}



[解决办法]
string sql = "select * from admin where user= ' " +struser + " ' and password= ' " + strpwd+ " ' ";
上句差了个双引号。
[解决办法]
string sql = "select * from admin where user= " +struser + " and password= " + strpwd;
===================================================================================

string sql = "select * from [admin] where [user] = ' " + struser + " ' and [password]= ' " + strpwd + " ' ";



[解决办法]
user= ' " +struser + " '

在SQL查询语句里,string格式的要用 ' '号包括起来。
那么在C#的语法里,引用变量要用双引号。在string里+代表连接字符传

热点排行