ExecuteReader返回行,但显示为0? [英] ExecuteReader returning rows but showing count as 0?

查看:214
本文介绍了ExecuteReader返回行,但显示为0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在这里,该过程被调用,并且该过程返回一行.这里的问题是ExecuteReader返回0行(跳过if节.我想知道它是怎么发生的

此处需要考虑的其他问题是为输出参数分配了返回值(但计数为0).请参见下面的代码.

Hi,

Here the procedure is called and the procedure is returning a row. The problem here is ExecuteReader is returning 0 rows( ,which skips the if section.I wonder how it''s happening

Other concern here is output parameter is assigned with returned value(but count is 0). See code below.

SqlConnection cn=new SqlConnection(ConfigurationManager.AppSettings["CS_localsource"]);
            
            SqlCommand cmd = new SqlCommand("validatelogin",cn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter param1 =new SqlParameter("@usename",SqlDbType.VarChar,300);
            param1.Direction=ParameterDirection.Input;
            param1.Value=textBox1.Text;
            SqlParameter param2=new SqlParameter("@password",SqlDbType.VarChar,300);
            param2.Direction=ParameterDirection.Input;
            param2.Value=textBox2.Text;
            SqlParameter param3=new SqlParameter("@formname",SqlDbType.VarChar,500);
            param3.Direction=ParameterDirection.Output;
            cmd.Parameters.Add(param1);
            cmd.Parameters.Add(param2);
            cmd.Parameters.Add(param3);
            cn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
        
           if (dr.Read())
           {
               MessageBox.Show("Test"+param3.Value);
           }
           else
           {
               label3.Enabled = true;
               label3.Text = "Invalid Username and Password";
               label3.BackColor = Color.Red;
                
           }
           cn.Close();
        }



非常感谢您的帮助.



Any help is greatly appreciated.

推荐答案

更改此部分

change this part

while (dr.Read())
{
  MessageBox.Show("Test"+param3.Value);
}


这篇关于ExecuteReader返回行,但显示为0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆