SQL存储过程:
CREATE PROCEDURE proc_test
@username char(10),
@password  varchar(50)
AS
select * from test where username=@username and password=@password//存储过程调用,登陆功能
              string username = textBox1.Text;
            string password = textBox2.Text;
            string strconn = "Server='.';Initial Catalog='lv';user id='sa';pwd='sa';Connect Timeout='30'";
            string strsql = "select * from test where username='"+textBox1.Text +"'and password='"+textBox2.Text+"' ";
            SqlConnection myConn = new SqlConnection(strconn);
            SqlCommand myComm = new SqlCommand("proc_test",myConn);
            myComm.CommandType = CommandType.StoredProcedure;            SqlParameter myPara = new SqlParameter("@username",SqlDbType.Char,10);
            myPara.Value = username;
            myComm.Parameters.Add(myPara);             myPara = new SqlParameter("@password",SqlDbType.NVarChar,50);
             myPara.Value = password;
            myComm.Parameters.Add(myPara);
            myConn.Open();
            if(myComm.ExecuteNonQuery()>0)
            {
                MessageBox.Show("成功进入!");
            }登陆的时候没有反映,不知道错在什么地方,请帮我看看,各问,我是初次弄存储过程

解决方案 »

  1.   

    string username = textBox1.Text; 
                string password = textBox2.Text; 存贮过程能直接引用控件的值吗?应该把控件的值传给存贮过程吧?
      

  2.   

    已经用存储过程了,sql语句过来凑什么热闹
      

  3.   

    string username = textBox1.Text;
    string password = textBox2.Text;
    string strconn = "Server='.';Initial Catalog='lv';user id='sa';pwd='sa';Connect Timeout='30'";SqlConnection myConn = new SqlConnection(strconn);
    SqlCommand myComm = new SqlCommand("proc_test", myConn);
    myComm.CommandType = CommandType.StoredProcedure;myComm.Parameters.AddWithValue("@username", username);
    myComm.Parameters.AddWithValue("@password", password);
    myConn.Open();SqlDataReader dr = myComm.ExecuteReader();if(dr.HasRows)
    {
        MessageBox.Show("成功进入!");
    }dr.Close();
    myConn.Close();
      

  4.   

    你需要的是读取查询的结果判断,而不仅仅是执行所以需要用ExecuteReader()方法而不是ExecuteNonQuery()方法
      

  5.   

    按下面稍微修改下,看看行不行!还有你既然用存储过程了,SQL语句就别写了!
    SQL存储过程: 
    CREATE PROCEDURE proc_test 
    @username char(10), 
    @password  varchar(50) 
    AS 
    select count(*) from test where username=@username and password=@password if(Convert.ToInt32(myComm.ExecuteScalar()==1
                { 
                    MessageBox.Show("成功进入!"); 
                } 
      

  6.   

    3楼的正解 CSDN真垃圾  
    我草 回复内容多长才算长啊
      

  7.   

    这种还验证还要用进程吗?不明白怎么想的。用一条sql语句就行了啊。