日期:2014-05-17  浏览次数:20500 次

如何封装该存储过程的方法
public static string checkUser(string UserName, string PassWord)
  {
  try
  {
  string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
  SqlConnection conn = new SqlConnection(connectionString);
  conn.Open();
  SqlCommand cmd = new SqlCommand("PRO_LOGIN", conn);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.Add(new SqlParameter("@UNAME", SqlDbType.VarChar, 200));
  cmd.Parameters["@UNAME"].Value = UserName;
  cmd.Parameters.Add(new SqlParameter("@UPWD", SqlDbType.VarChar, 200));
  cmd.Parameters["@UPWD"].Value = PassWord;
  cmd.Parameters.Add(new SqlParameter("@MESSAGE", SqlDbType.VarChar, 200));
  cmd.Parameters["@MESSAGE"].Direction = ParameterDirection.Output;
  cmd.ExecuteNonQuery();
  string backString = cmd.Parameters["@MESSAGE"].Value.ToString();
  cmd.Dispose();
  conn.Close();
  return backString;

  }
  catch (System.Data.SqlClient.SqlException E)
  {
  throw new Exception(E.Message);
  }



  }
  }


对于以上方法 如何将其封装? 让ado.net对象的调用不要混在这个方法里面独立出来!

------解决方案--------------------
Refer:
http://www.cnblogs.com/insus/articles/1654653.html