前台页面 visa.com ;程序页面 nation.aspx.cs ;.bll Td_CountryManager.cs ;
.DAL Td_CountryService.cs ; DBHelper.cs 程序
1 前台页面 visa.com
<ul>
<asp:Repeater ID="Repeatergjc" runat="server">
<ItemTemplate>
<li><p id="qqgj"><a href='nation_<%#Eval("CouEname") %>.html'><%#Eval("CouName") %></a></p><p id="qqprice">¥<%#Eval("CouPrice")%>起</p><div class="clear"></div></li>
</ItemTemplate>
</asp:Repeater>
</ul>
2 后台程序nation.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string get = Request.QueryString["id"].ToString();
string[] array = get.Split('_');
string id = array[1];
// 你提交过来的是国家的拼音了,这个地方就不能把收到的编号设置为int格式了,否则肯定是会报错的
cont = Td_CountryManager.GetTd_CountryByCouEname(id);
//签证大区
string sql = string.Format("select * from td_region where countryid={0}", id);
Repeaterdq.DataSource = Td_RegionManager.SelectAllTd_RegionsBySql(sql);
Repeaterdq.DataBind();
//签证类型
string qzzl = "";
sql = string.Format("select visaname from td_visa where visaregionid in(select regionid from td_region where countryid={0})and visatype=1 group by visaname", id);
DataTable table = DBHelper.GetTable(sql);
foreach (DataRow row in table.Rows)
{
qzzl += "<li><p style='width:330px;'>" + row["visaname"].ToString() + daqu(id, row["visaname"].ToString()) + "</p></li>";
}
Literal1.Text = qzzl; sql = string.Format("select top 10 * from td_question where countryid={0} order by questiontime desc", id);
Repeaterwt.DataSource = Td_QuestionManager.SelectAllTd_QuestionsBySql(sql);
Repeaterwt.DataBind();
sql = "select top 10 * from td_message where messagetype=5 order by messagetime desc";
Repeaterkx.DataSource = Td_MessageManager.SelectAllTd_MessagesBySql(sql);
Repeaterkx.DataBind();
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(2);
3 方法.DAL public static Td_Country SelectTd_CountryByCouEname(string CouEname)
{
Td_Country info = null;//返回值
string sql = string.Format("SELECT * FROM Td_Country WHERE CouEname like '%s'", CouEname);
IList<Td_Country> list = SelectTd_CountriesBySql(sql);
if (list.Count > 0)
{
info = list[0];
}
return info;
}
.BLL
public static Td_Country GetTd_CountryByCouEname(string CouEname)
{
return Td_CountryService.SelectTd_CountryByCouEname(CouEname);
}.DBHelper.cs
public static DataTable GetTable(string sql, params SqlParameter[] values)
{
DataTable dt = new DataTable();//返回值
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(sql, conn);
if (values != null)
{
cmd.Parameters.AddRange(values);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Open();
da.Fill(dt);
}
return dt;
}运行时错误提示
1 nation.aspx.csstring qzzl = "";
sql = string.Format("select visaname from td_visa where visaregionid in(select regionid from td_region where countryid={0})and visatype=1 group by visaname", id);
DataTable table = DBHelper.GetTable(sql);
foreach (DataRow row in table.Rows)
{
qzzl += "<li><p style='width:330px;'>" + row["visaname"].ToString() + daqu(id, row["visaname"].ToString()) + "</p></li>"; }
Literal1.Text = qzzl;红色代码处错误提示(1)参数 1: 无法从“string”转换为“int” (2)与“nation.daqu(int, string)”最匹配的重载方法具有一些无效参数2 .DBHelper.cs
da.Fill(dt); 提示:列名无效
.DAL Td_CountryService.cs ; DBHelper.cs 程序
1 前台页面 visa.com
<ul>
<asp:Repeater ID="Repeatergjc" runat="server">
<ItemTemplate>
<li><p id="qqgj"><a href='nation_<%#Eval("CouEname") %>.html'><%#Eval("CouName") %></a></p><p id="qqprice">¥<%#Eval("CouPrice")%>起</p><div class="clear"></div></li>
</ItemTemplate>
</asp:Repeater>
</ul>
2 后台程序nation.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string get = Request.QueryString["id"].ToString();
string[] array = get.Split('_');
string id = array[1];
// 你提交过来的是国家的拼音了,这个地方就不能把收到的编号设置为int格式了,否则肯定是会报错的
cont = Td_CountryManager.GetTd_CountryByCouEname(id);
//签证大区
string sql = string.Format("select * from td_region where countryid={0}", id);
Repeaterdq.DataSource = Td_RegionManager.SelectAllTd_RegionsBySql(sql);
Repeaterdq.DataBind();
//签证类型
string qzzl = "";
sql = string.Format("select visaname from td_visa where visaregionid in(select regionid from td_region where countryid={0})and visatype=1 group by visaname", id);
DataTable table = DBHelper.GetTable(sql);
foreach (DataRow row in table.Rows)
{
qzzl += "<li><p style='width:330px;'>" + row["visaname"].ToString() + daqu(id, row["visaname"].ToString()) + "</p></li>";
}
Literal1.Text = qzzl; sql = string.Format("select top 10 * from td_question where countryid={0} order by questiontime desc", id);
Repeaterwt.DataSource = Td_QuestionManager.SelectAllTd_QuestionsBySql(sql);
Repeaterwt.DataBind();
sql = "select top 10 * from td_message where messagetype=5 order by messagetime desc";
Repeaterkx.DataSource = Td_MessageManager.SelectAllTd_MessagesBySql(sql);
Repeaterkx.DataBind();
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(2);
3 方法.DAL public static Td_Country SelectTd_CountryByCouEname(string CouEname)
{
Td_Country info = null;//返回值
string sql = string.Format("SELECT * FROM Td_Country WHERE CouEname like '%s'", CouEname);
IList<Td_Country> list = SelectTd_CountriesBySql(sql);
if (list.Count > 0)
{
info = list[0];
}
return info;
}
.BLL
public static Td_Country GetTd_CountryByCouEname(string CouEname)
{
return Td_CountryService.SelectTd_CountryByCouEname(CouEname);
}.DBHelper.cs
public static DataTable GetTable(string sql, params SqlParameter[] values)
{
DataTable dt = new DataTable();//返回值
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(sql, conn);
if (values != null)
{
cmd.Parameters.AddRange(values);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Open();
da.Fill(dt);
}
return dt;
}运行时错误提示
1 nation.aspx.csstring qzzl = "";
sql = string.Format("select visaname from td_visa where visaregionid in(select regionid from td_region where countryid={0})and visatype=1 group by visaname", id);
DataTable table = DBHelper.GetTable(sql);
foreach (DataRow row in table.Rows)
{
qzzl += "<li><p style='width:330px;'>" + row["visaname"].ToString() + daqu(id, row["visaname"].ToString()) + "</p></li>"; }
Literal1.Text = qzzl;红色代码处错误提示(1)参数 1: 无法从“string”转换为“int” (2)与“nation.daqu(int, string)”最匹配的重载方法具有一些无效参数2 .DBHelper.cs
da.Fill(dt); 提示:列名无效
解决方案 »
- [求教:GridView 分组全选问题]
- 设置 DataSource 属性后无法修改项集合。
- 菜鸟问题:using(OleDbConnection connection = new OleDbConnection(connectionString))
- 1分钟写个JAVASCRIPT验证,速度结贴
- Timer和MouseWheel冲突?
- [急 来者有分] Lucene问题 做过的近来看看 没做过的进来顶一下
- 图象处理
- 如何刷新TreeView界面?
- 如何把位数组转换成字节
- 求救!我的Aspx文件可以运行,但Asp文件却不能运行了!
- datagridview单元格赋值问题
- 引用ashx文件的session时,出现未将对象引用到对象的实例
与“nation.daqu(int, string)”匹配的重载方法具有一些无效参数 就解决了
列名无效:这个检查你的sql语句
另外说,sql语句这样,可能会有很严重的安全隐患的