Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

c# - I'm unable to login any suggestions, both in case of stored procedure and codebehind

CREATE TABLE MYUSE100(userid number,username varchar2(45),ppassword varchar2(50));
insert into MYUSE200 values('harry','potter');

here is my stored procedure

create or replace procedure  p_myuse200(p_username1 in  varchar2,p_password1 in varchar2,v_count out number)
AS
BEGIN
select count(*) INTO v_count from MYUSE200 where username1=p_username1 and password1=p_password1;
IF v_count>0 THEN
v_count:=v_count+0;
ELSE
v_count:=0;
END IF;
END;
/

codebehind

protected void button1_onclick(object sender, EventArgs e)
    {

        OracleConnection conn = new OracleConnection(strConnString);


        OracleCommand cmd = new OracleCommand("p_myuse200",conn);
        cmd.CommandType = CommandType.StoredProcedure;
        conn.Open();
        OracleParameter username1 = new OracleParameter("p_username1", OracleDbType.Varchar2, 50);
        username1.Value = textbox1.Text;
        cmd.Parameters.Add(username1);

        OracleParameter password1 = new OracleParameter("p_password1 ", OracleDbType.Varchar2, 45);
        password1.Value = textbox2.Text;
        cmd.Parameters.Add(password1);

        cmd.Parameters.Add("v_count", OracleDbType.Varchar2, 30);
        cmd.Parameters["v_count"].Direction = ParameterDirection.Output;


             Int32 results = 0;

          //results = (Int32)cmd.Parameters["v_count"].Value;

           try
            {
                results = Convert.ToInt32(cmd.Parameters["values"].Value);
                cmd.ExecuteScalar();
               //cmd.ExecuteNonQuery();
                if (results > 0)
                {
                    Response.Redirect("http://www.google.com");
                }
                else
                {
                    Response.Redirect("http://www.facebook.com");
                }
                conn.Close();
                conn.Dispose();
            }

            catch (Exception ex)
            {
             Response.Redirect("http://www.gmail.com");
            }
}
}

I'm unable to login any suggestions, both in case of stored procedure and codebehind. results>0 is not getting the current value count=1 and results should be 1 but it is always zero and else block is executing,,,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ExecuteScalar executes the query, and returns the first column of the first row in the result set returned by the query. You should get the results from the query like this:

var results = (int) ExecuteScalar();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...