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("成功进入!");
}登陆的时候没有反映,不知道错在什么地方,请帮我看看,各问,我是初次弄存储过程
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("成功进入!");
}登陆的时候没有反映,不知道错在什么地方,请帮我看看,各问,我是初次弄存储过程
string password = textBox2.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();
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("成功进入!");
}
我草 回复内容多长才算长啊