asp.net 网站代码本地和服务器是一样的,但是测试的结果却不同!!!
网站代码是在本地改好测试没问题后再上传到服务器上的,本地能取到数据表中对应参数所有的记录,但是远程浏览器测试时只能取到一条,且每个参数下取到的都是相同的!前台代码
<asp:Repeater ID="Repeaterlx" runat="server">
<ItemTemplate>
<div class="ya">
<div class="ya_top">
<div class="n_jia">签证名称:</div>
<div class="nnn1"><%#Eval("VisaName") %></div>
<div class="nnn2">¥<%#Eval("VisaPrice") %></div>
<div class="nnn3">领区</div>
<div class="nnn4">有效期</div>
<div class="nnn5">最多停留</div>
<div class="nnn6">工作日</div>
<div class="nnn7">邀请函</div>
<div class="nnn8">面试</div>
<div class="nnn9">预约</div>
<div class="nnn10">签证费</div>
</div>
<div class="ya_bottom">
<div class="bbb2"><%#Eval("FK_VisaRegion.RegionName") %></div>
<div class="bbb3"><%#Eval("VisaTime") %></div>
<div class="bbb4"><%#Eval("VisaStop")%></div>
<div class="bbb5"><%#Eval("VisaSqys") %></div>
<div class="bbb6"><%#Eval("Visayqh") %></div>
<div class="bbb7"><%#Eval("Visams") %></div>
<div class="bbb8"><%#Eval("Visayy") %></div>
<div class="bbb9"><%#Eval("Visaqzf") %></div>
<ul class="bbb10">
<li>
<%#Eval("VisaIntro") %>
</li>
</ul>
<div class="bbb12">
<a href='visacontent_<%#Eval("VisaId") %>.html'>查看详情</a>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
后台程序
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using visa.BLL;
using visa.Models;
public partial class visalist : System.Web.UI.Page
{
protected Td_Region region;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string get = Request.QueryString["id"].ToString();
string[] array = get.Split('_');
string name = array[2];
region = Td_RegionManager.GetTd_RegionByRegionEname(name);
int id = region.RegionId;
string type = array[1];
string sql = "";
int typeid = 0;
if (type == "q")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='1'", id);
typeid = 2;
}
if (type == "j")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='2'", id);
typeid = 3;
}
region = Td_RegionManager.GetTd_RegionByRegionId(id);
Repeaterlx.DataSource = Td_VisaManager.SelectAllTd_VisasBySql(sql);
Repeaterlx.DataBind();
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(typeid);
//国家region.FK_Country.CouName;
//大区 region.RegionName;
LtlKword.Text = "<title>" + kword.KwordTitle + "</title><meta name=\"keywords\" content=\"" + kword.KwordKey + "\" /><meta name=\"description\" content=\"" + kword.KwordDescribe + "\"/>";
}
}
}
--------------------编程问答-------------------- Td_RegionManager.cs代码
public static Td_Region GetTd_RegionByRegionEname(string regionEname)
{
return Td_RegionService.SelectTd_RegionByRegionEname(regionEname);
}
Td_RegionService.cs代码
//============================================================--------------------编程问答-------------------- 数据库也一样吗?记录和记录数也一样? --------------------编程问答-------------------- 数据库一样,只是记录数不一样,但是服务器数据表中有的记录也读不出来!!
// 项目: visa
// 版本: 1.0
// 作者: chenchangjie
// 时间: 2012-4-20 9:15:57
//============================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using visa.Models;
namespace visa.DAL
{
public static partial class Td_RegionService
{
public static int InsertTd_Region(Td_Region td_Region)
{
//定义sql语句
string sql =
"INSERT Td_Region (CountryId, RegionName, RegionImage, RegionCountent,RegionEname)" +
"VALUES (@CountryId, @RegionName, @RegionImage, @RegionCountent,@RegionEname);select @@identity";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@CountryId", td_Region.CountryId),
new SqlParameter("@RegionName", td_Region.RegionName),
new SqlParameter("@RegionImage", td_Region.RegionImage),
new SqlParameter("@RegionCountent", td_Region.RegionCountent),
new SqlParameter("@RegionEname", td_Region.RegionEname)
};
//执行sql语句
return DBHelper.GetScalar(sql, para);
}
public static void DeleteTd_Region(Td_Region td_Region)
{
DeleteTd_RegionByRegionId(td_Region.RegionId);
}
public static void DeleteTd_RegionByRegionId(int regionId)
{
//定义sql语句
string sql = "DELETE Td_Region WHERE RegionId = @RegionId";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@RegionId", regionId)
};
//执行sql语句
DBHelper.ExecuteCommand(sql, para);
}
public static void UpdateTd_Region(Td_Region td_Region)
{
//定义sql语句
string sql =
"UPDATE Td_Region " +
"SET " +
"CountryId = @CountryId ," +
"RegionName = @RegionName ," +
"RegionImage = @RegionImage ," +
"RegionCountent = @RegionCountent " +
"RegionEname = @RegionEname ," +
"WHERE RegionId = @RegionId";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@RegionId", td_Region.RegionId),
new SqlParameter("@CountryId", td_Region.CountryId),
new SqlParameter("@RegionName", td_Region.RegionName),
new SqlParameter("@RegionImage", td_Region.RegionImage),
new SqlParameter("@RegionCountent", td_Region.RegionCountent),
new SqlParameter("@RegionEname", td_Region.RegionEname)
};
//执行sql语句
DBHelper.ExecuteCommand(sql, para);
}
public static Td_Region SelectTd_RegionByRegionId(int regionId)
{
Td_Region info = null;//返回值
string sql = string.Format("SELECT * FROM Td_Region WHERE RegionId = {0}", regionId);
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;
}
}
}
--------------------编程问答-------------------- 你用sqlserver跟踪器跟踪一sql语句,然后在sql里查下看看到底这条语句查询出什么结果 --------------------编程问答-------------------- 用SqlServer profiler 抓sql语句 看看就知道了 --------------------编程问答-------------------- 这是数据表中的记录,http://www.400visa.com/visalist_q_beijing.html 测试 ,只能得到一条啊
--------------------编程问答-------------------- 图传错了!
--------------------编程问答-------------------- 不会用! --------------------编程问答-------------------- 百度一下了.有图说明 --------------------编程问答-------------------- 嗯 --------------------编程问答-------------------- 先不说别的,只读一条记录,貌似C#里面有个方法是只读出一条记录的。貌似ExecuteScalar()这个函数就是只读一样或者一列的,你看看你是不是用到了这个方法。。。 --------------------编程问答-------------------- 把sql语句单显示出来,放到数据库上去测,看到底有多少条记录,然后就知道大概是代码问题,还是sql或库的问题了 --------------------编程问答-------------------- 测试了,无论本地还是服务器数据库,符合条件的记录都能读出来,不止一条 --------------------编程问答-------------------- 应该是代码方面的问题的可能性打了。在程序中多设几个数据显示的点,看出来的结果和期望的是否一致,是能发现问题所在的 --------------------编程问答-------------------- 把执行的sql 放到查询分析器执行下 --------------------编程问答-------------------- 我找到问题的原因,程序没有执行
if (type == "q")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='1'", id);
typeid = 2;
}
if (type == "j")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='2'", id);
typeid = 3;
}
这段代码, 直接进入后台执行region = Td_RegionManager.GetTd_RegionByRegionEname(name);,那我现在要怎么才能让程序先执行if (type == "q")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='1'", id);
typeid = 2;
}
if (type == "j")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='2'", id);
typeid = 3;
},呢
using System.Web.Security;--------------------编程问答-------------------- 我现在只想通过 region = Td_RegionManager.GetTd_RegionByRegionEname(name);
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using visa.BLL;
using visa.Models;
public partial class visalist : System.Web.UI.Page
{
protected Td_Region region;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string get = Request.QueryString["id"].ToString();
string[] array = get.Split('_');
string name = array[2];
region = Td_RegionManager.GetTd_RegionByRegionEname(name);
int id = region.RegionId;
string type = array[1];
string sql = "";
int typeid = 0;
if (type == "q")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='1'", id);
typeid = 2;
}
if (type == "j")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='2'", id);
typeid = 3;
}
region = Td_RegionManager.GetTd_RegionByRegionId(id);
Repeaterlx.DataSource = Td_VisaManager.SelectAllTd_VisasBySql(sql);
Repeaterlx.DataBind();
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(typeid);
//国家region.FK_Country.CouName;
//大区 region.RegionName;
LtlKword.Text = "<title>" + kword.KwordTitle + "</title><meta name=\"keywords\" content=\"" + kword.KwordKey + "\" /><meta name=\"description\" content=\"" + kword.KwordDescribe + "\"/>";
}
}
}
int id = region.RegionId; 这个方法得到td_region数据表记录的id,但是现在在执行这个方法的过程中后台已经把程序走了一遍,导致只能读取表中的第一条记录,根本没有执行
if (type == "q")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='1'", id);
typeid = 2;
}
if (type == "j")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='2'", id);
typeid = 3;
}
所以得不到表td_visa中匹配的记录,那我怎么才能只得到td_region数据表记录的id,同时不阅遍数据表,程序继续运行根据id通过以下方法
f (type == "q")在阅历数据表啊 --------------------编程问答-------------------- --------------------编程问答-------------------- 一般引起数据问题就是环境变化引起的,你只看到代码有没有问题,就没考虑过你服务器环境和你本地有什么不同吗?比如数据库 --------------------编程问答-------------------- 我发现问题了,是代码在执行过程中调用方法执行顺序 有问题,但是不知道怎么改 --------------------编程问答--------------------
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='1'", id);
typeid = 2;
}
if (type == "j")
{
sql = string.Format("select * from td_visa where visaregionid={0} and visatype='2'", id);
typeid = 3;
}
region = Td_RegionManager.GetTd_RegionByRegionId(id);
Repeaterlx.DataSource = Td_VisaManager.SelectAllTd_VisasBySql(sql);
Repeaterlx.DataBind();
那就按照正确的逻辑思维改呗
补充:.NET技术 , C#