public SqlDataReader GetUserLoginByProc(string sUserName,string sPassword)
{
///创建链接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); ///创建Command
SqlCommand myCommand = new SqlCommand("Pr_GetUserLogin",myConnection);
///设置为执行存储过程
myCommand.CommandType = CommandType.StoredProcedure; ///添加存储过程的参数
SqlParameter pUserName = new SqlParameter("@UserName",SqlDbType.VarChar,32);
pUserName.Value = sUserName;
myCommand.Parameters.Add(pUserName); SqlParameter pPassword = new SqlParameter("@Password",SqlDbType.VarChar,255);
pPassword.Value = sPassword;
myCommand.Parameters.Add(pPassword); ///定义DataReader
SqlDataReader dr = null;
try
{
///打开链接
myConnection.Open();
///读取数据
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(SqlException ex)
{
///抛出异常
throw new Exception(ex.Message,ex);
}
///返回DataReader
return dr;
}
这里调用上边的方法 user.Encrypt 是加密程序
SqlDataReader recu = user.GetUserLoginByProc(sUserName,
user.Encrypt(sPassword));我想知道 是怎么发参数传过去的 在方法中又是怎么使用传递的参数
{
///创建链接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); ///创建Command
SqlCommand myCommand = new SqlCommand("Pr_GetUserLogin",myConnection);
///设置为执行存储过程
myCommand.CommandType = CommandType.StoredProcedure; ///添加存储过程的参数
SqlParameter pUserName = new SqlParameter("@UserName",SqlDbType.VarChar,32);
pUserName.Value = sUserName;
myCommand.Parameters.Add(pUserName); SqlParameter pPassword = new SqlParameter("@Password",SqlDbType.VarChar,255);
pPassword.Value = sPassword;
myCommand.Parameters.Add(pPassword); ///定义DataReader
SqlDataReader dr = null;
try
{
///打开链接
myConnection.Open();
///读取数据
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(SqlException ex)
{
///抛出异常
throw new Exception(ex.Message,ex);
}
///返回DataReader
return dr;
}
这里调用上边的方法 user.Encrypt 是加密程序
SqlDataReader recu = user.GetUserLoginByProc(sUserName,
user.Encrypt(sPassword));我想知道 是怎么发参数传过去的 在方法中又是怎么使用传递的参数
pUserName.Value = sUserName; //给参数赋值
myCommand.Parameters.Add(pUserName); //将参数添加到myCommand中因为myCommand.CommandType = CommandType.StoredProcedure;
已经定义了myCommand对应的是存储过程
user.Encrypt(sPassword)); 这样已经传过去了.不应该有疑问啊.
顺着代码看就明白了,而且鼠标移到方法上都有提示,哪里不明白呢.
这个传值就跟赋值一样.
你这个使用存储过程的方法和调用方法的代码都写好了,
你是想问怎么写存储过程吗?
存储过程该怎么写,还是怎么写
定义两个输入参数,写select语句时,把用户名和密码当作查询条件就可以了