标签:os io ar 数据 cti sp log on c
CREATE PROCEDURE ProGetPWD
@username varchar(20),
@password varchar(20) OUTPUT
AS
BEGIN
SELECT @password = password
FROM Users
WHERE username = @username
END
string sql = "Data Source=.;Initial Catalog=Test;Integrated Security=True;";
using (SqlConnection conn = new SqlConnection(sql))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
//设置要调用的存储过程的名称
cmd.CommandText = "GetuserPwd";
//指定SqlCommand对象传给数据库的是存储过程的名称而不是sql语句
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter userName = cmd.Parameters.Add(new SqlParameter("@userName", SqlDbType.VarChar, 20));
//指明"@userName"是输入参数
userName.Direction = ParameterDirection.Input;
//为@userName参数赋值
userName.Value = txtUserName.Text;
SqlParameter userPwd = cmd.Parameters.Add(new SqlParameter("@userPwd", SqlDbType.VarChar, 20));
//指明"@userPwd"是输出参数
userPwd.Direction = ParameterDirection.Output;
//执行
cmd.ExecuteNonQuery();
//得到输出参数的值,把赋值给name,注意,这里得到的是object类型的,要进行相应的类型轮换
string passwrod = Convert.ToString(cmd.Parameters["@userPwd"].Value);
MessageBox.Show(passwrod);
}
标签:os io ar 数据 cti sp log on c
原文地址:http://www.cnblogs.com/lschenblog/p/3953900.html