SqlConnection con=lizi.connection();         //    连接数据库  SqlCommand cmd=new SqlCommand();                //创建cmd string sql="select * from lizi where id=@id and pwd=@pwd";               //SQL命令(参数化) cmd.Connection=con;                                     //连接cmd
cmd.CommandText=sql;                                     //设置sql执行命令
SqlParameter id = new SqlParameter();                  
id.ParameterName="@id";
id.Size=100;                                                   //创建 @id 参数
id.SqlDbType=SqlDbType.VarChar;
id.Value=name.Text.ToString();                           
     
SqlParameter pwd= new SqlParameter();                       //创建 @pwd 参数
pwd.ParameterName="@pwd";
pwd.Size=100;
pwd.SqlDbType=SqlDbType.VarChar;
pwd.Value=mima.Text.ToString();

 
cmd.Parameters.Add(id);                                   //向cmd里添加参数 @id
cmd.Parameters.Add(pwd);                           //向cmd里添加参数 @pwd
SqlDataReader red = cmd.ExecuteReader();       //创建 sqldatareader  if(red.HasRows)
{
Label3.Text="欢迎"+red["longmoney"];
a11.DataSource=red;
a11.DataBind();
}
else
{
Response.Write("没有数据");
}
red.Close();
con.Close();提示着句有错 Label3.Text="欢迎"+red["longmoney"];
 在没有任何数据时进行无效的读取尝试。数据库中已经有表
id | pwd |longmoney|
777| 777 |  10000  |@id=777
@pwd=777为什么 Label3.Text="欢迎"+red["longmoney"];着句告诉我说
在没有任何数据时进行无效的读取尝试。

解决方案 »

  1.   

    不行啊还是提示
    “/proc”应用程序中的服务器错误。
    --------------------------------------------------------------------------------在没有任何数据时进行无效的读取尝试。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 在没有任何数据时进行无效的读取尝试。源错误: 
    行 88:  Panel1.Visible=false;
    行 89:  rq.Visible=true;
    行 90:  Label3.Text="欢迎"+red["longmoney"].ToString();
    行 91: 
    行 92:  }
     
      

  2.   

    if(red.HasRows)
    {
        Label3.Text="欢迎"+red["longmoney"];
    ...改为 
    if(red.Read())
    {
        Label3.Text="欢迎"+red["longmoney"];
    ...