asp.net网站 前台参数由之前的id 变为name 结果只能读到数据表中的第一条记录
一个签证网站http://www.400visa.com/American_qianzheng.html 前台页面之前是有对应的id作为参数传到后台,现在为了利于收录,把参数id改为name,后台利用三层架构,添加了方法
public static Td_Region SelectTd_RegionByRegionEname(string regionEname)
{
Td_Region info = null;//返回值
string sql = string.Format("SELECT * FROM Td_Region WHERE regionEname =\'{0}\'", regionEname);
IList<Td_Region> list = SelectTd_RegionsBySql(sql);
if (list.Count > 0)
{
info = list[0];
}
return info;
}
public static Td_Region SelectTd_RegionByRegionEname(string regionEname)
{
Td_Region info = null;//返回值
string sql = string.Format("SELECT * FROM Td_Region WHERE regionEname =\'{0}\'", regionEname);
IList<Td_Region> list = SelectTd_RegionsBySql(sql);
if (list.Count > 0)
{
info = list[0];
}
return info;
}
public static Td_Region SelectOneTd_RegionBySql(string sql)
{
Td_Region info = null;//返回值
IList<Td_Region> list = SelectTd_RegionsBySql(sql);
if (list.Count > 0)
{
info = list[0];
}
return info;
}
public static IList<Td_Region> SelectAllTd_Regions()
{
string sql = "SELECT * FROM Td_Region";
return SelectTd_RegionsBySql(sql);
}
public static IList<Td_Region> SelectAllTd_RegionsBySql(string sql)
{
return SelectTd_RegionsBySql(sql);
}
public static IList<Td_Region> SelectTd_RegionsByCountryId(int countryId)
{
string sql = string.Format("SELECT * FROM Td_Region WHERE CountryId={0}", countryId);
return SelectTd_RegionsBySql(sql);
}
private static IList<Td_Region> SelectTd_RegionsBySql(string safeSql)
{
return SelectTd_RegionsBySql(safeSql, null);
}
private static IList<Td_Region> SelectTd_RegionsBySql(string sql, params SqlParameter[] values)
{
IList<Td_Region> list = new List<Td_Region>();//返回值
DataTable table = DBHelper.GetTable(sql, values);
foreach (DataRow row in table.Rows)
{
Td_Region td_Region = new Td_Region();
if (!Convert.IsDBNull(row["RegionId"]))
{
td_Region.RegionId = (int)row["RegionId"];
}
if (!Convert.IsDBNull(row["CountryId"]))
{
td_Region.CountryId = (int)row["CountryId"];
}
if (!Convert.IsDBNull(row["RegionName"]))
{
td_Region.RegionName = (string)row["RegionName"];
}
if (!Convert.IsDBNull(row["RegionImage"]))
{
td_Region.RegionImage = (string)row["RegionImage"];
}
if (!Convert.IsDBNull(row["RegionCountent"]))
{
td_Region.RegionCountent = (string)row["RegionCountent"];
}
if (!Convert.IsDBNull(row["RegionEname"]))
{
td_Region.RegionEname = (string)row["RegionEname"];
}
td_Region.FK_Country = Td_CountryService.SelectTd_CountryByCouId((int)row["CountryId"]); //FK
list.Add(td_Region);
}
return list;
}
}
string sql = string.Format("SELECT * FROM Td_Region WHERE regionEname =\'{0}\'", regionEname); IList<Td_Region> list = SelectTd_RegionsBySql(sql);
string sql = string.Format("SELECT * FROM Td_Region WHERE regionEname = @regionEnamel", regionEname);
SqlParameter[] parms={new SqlParameter("regionEname",regionEname)};
IList<Td_Region> list = SelectTd_RegionsBySql(sql,params);
public static Td_Region SelectTd_RegionByRegionEname(string regionEname) { Td_Region info = null;//返回值 string sql = string.Format("SELECT * FROM Td_Region WHERE regionEname =\'{0}\'", regionEname); IList<Td_Region> list = SelectTd_RegionsBySql(sql); if (list.Count > 0) { info = list[0]; } return info; }
if (list.Count > 0)
{
info = list[0];
}
return info;