调用数据层参数传递问题!
假设要实现这样的功能:
public void chkuser()
{
string sql = "select * from Table where name = @username ";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings[ "ConnStr "]);//ConnStr为数据库连接语句
SqlCommand cmd = new SqlCommand(sql,cn);
cmd.Parameters.Add( "@username ",SqlDbType.VarChar,50).Value=username.Text//username.Text为表单用户输入的用户名
............
}
数据层:
public static SqlDataReader ExecuteReader(string sql, SqlParameter[] args)
{
cn = new SqlConnection(ConnStr);
cmd = new SqlCommand(sql,cn);
foreach(SqlParameter[] i in args)
{
cmd.Parameters.Add(args);
}
try
{
&nb