登陆数据库存储过程

来源:百度知道 编辑:UC知道 时间:2024/05/12 19:39:11
大家好,我是一名初学者。请大家帮帮忙。先谢谢了。
如果数据库的存储过程这样
create procedure UserLanding(
@username varchar(50),
@userpassword varchar(50),
@record tinyint output
)
as
if exists(select * from users where username=@username and
userpassword=@userpassword)
begin
set @record=1
end
else
begin
set @record=0
end
那么vs中的类方法应该怎么写最好最简单。希望大家写详细点。

private void StoredProcedure(String connectionString,String username,String password,String record)
{
SqlConnection sqlcon = new SqlConnection(connectionString);
SqlCommand sqlcom = new SqlCommand("UserLanding", sqlcon);
sqlcom.CommandType = CommandType.StoredProcedure;
sqlcom.Parameters.Add(username, SqlDbType.VarChar,50);
sqlcom.Parameters.Add(password, SqlDbType.VarChar,50);
sqlcom.Parameters.Add(record, SqlDbType.TinyInt);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
试试这个