/// <summary> /// 增加一条数据 /// </summary> public bool Add(AccountME model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into Account("); strSql.Append("userID,userName,roleName,userPassword)"); strSql.Append(" values ("); strSql.Append("@userID,@userName,@roleName,@userPassword)"); SqlParameter[] parameters = { new SqlParameter("@userID", SqlDbType.Decimal,5), new SqlParameter("@userName", SqlDbType.NVarChar,50), new SqlParameter("@roleName", SqlDbType.NVarChar,50), new SqlParameter("@userPassword", SqlDbType.NChar,6)}; parameters[0].Value = model.userID; parameters[1].Value = model.userName; parameters[2].Value = model.roleName; parameters[3].Value = model.userPassword; int rows = DbHelperSQL.ExecuteSql(PubConstant.ConnectionStringAccountDB,strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(AccountME model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update Account set "); strSql.Append("userID=@userID,"); strSql.Append("roleName=@roleName,"); strSql.Append("userPassword=@userPassword"); strSql.Append(" where userName=@userName "); SqlParameter[] parameters = { new SqlParameter("@userID", SqlDbType.Decimal,5), new SqlParameter("@roleName", SqlDbType.NVarChar,50), new SqlParameter("@userPassword", SqlDbType.NChar,6), new SqlParameter("@userName", SqlDbType.NVarChar,50)}; parameters[0].Value = model.userID; parameters[1].Value = model.roleName; parameters[2].Value = model.userPassword; parameters[3].Value = model.userName; int rows = DbHelperSQL.ExecuteSql(PubConstant.ConnectionStringAccountDB,strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public AccountME GetModel(string userName) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 userID,userName,roleName,userPassword from Account "); strSql.Append(" where userName=@userName "); SqlParameter[] parameters = { new SqlParameter("@userName", SqlDbType.NVarChar,50) }; parameters[0].Value = userName; AccountME model=new AccountME(); DataSet ds = DbHelperSQL.Query(PubConstant.ConnectionStringAccountDB,strSql.ToString(), parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["userID"]!=null && ds.Tables[0].Rows[0]["userID"].ToString()!="") { model.userID=decimal.Parse(ds.Tables[0].Rows[0]["userID"].ToString()); } if(ds.Tables[0].Rows[0]["userName"]!=null && ds.Tables[0].Rows[0]["userName"].ToString()!="") { model.userName=ds.Tables[0].Rows[0]["userName"].ToString(); } if(ds.Tables[0].Rows[0]["roleName"]!=null && ds.Tables[0].Rows[0]["roleName"].ToString()!="") { model.roleName=ds.Tables[0].Rows[0]["roleName"].ToString(); } if(ds.Tables[0].Rows[0]["userPassword"]!=null && ds.Tables[0].Rows[0]["userPassword"].ToString()!="") { model.userPassword=ds.Tables[0].Rows[0]["userPassword"].ToString(); } return model; } else { return null; } }