Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 18-May-11 7:34am
v3
Comments
Slacker007 18-May-11 6:41am    
Edited for spelling, readability, and code block.

1 solution

change this part

while (dr.Read())
{
  MessageBox.Show("Test"+param3.Value);
}
 
Share this answer
 
Comments
M.CHAITHANYA 18-May-11 7:57am    
Hi,

i tried with the code provided by you.Still i face the same problem.
fcronin 18-May-11 15:53pm    
Does your stored procedure contain a select statement at all, or just assigns the return value as param3?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900