public string[] pic = new string[5];
public string[] link = new string[5];
protected System.Web.UI.HtmlControls.HtmlGenericControl inde;
public string[] min=new string[5];
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection con = new SqlConnection("server=.;database=Systen;user id=sa;password=;");
string str_top="select top 5 category from product_category_table where grade=1 and changes=0 order by bys";
SqlDataAdapter da = new SqlDataAdapter(str_top, con);
StringBuilder sb_slist=new StringBuilder();
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
{
string str_Temp_Pic = "";
string str_Temp_Link = "";
string str_info = "select pr_image,pro_url from product_image where pro_type='" + ds.Tables[0].Rows[m][0].ToString() + "'";
SqlDataAdapter da1 = new SqlDataAdapter(str_info, con)
sb_slist.Append("<td align=\"center\" width=\"160\">");
sb_slist.Append(ds.Tables[0].Rows[m][0].ToString());
sb_slist.Append("<td>");
DataSet ds1 = new DataSet();
da1.Fill(ds1);
if (ds1.Tables[0].Rows.Count > 0)
{
for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)
{
str_Temp_Pic+="webupload/"+ds1.Tables[0].Rows[n][0].ToString() + "|";
str_Temp_Link += ds1.Tables[0].Rows[n][1].ToString() + "|";
//str_Temp_cname += ds.Tables[0].Rows[m][0].ToString() + "|";
}
}
pic[m] = str_Temp_Pic.Substring(0,str_Temp_Pic.Length - 1);
link[m] = str_Temp_Link.Substring(0, str_Temp_Link.Length - 1);
}
}
this.inde.InnerHtml=sb_slist.ToString();
}
为什么会报一个长度不能小于 0。参数名: length
public string[] link = new string[5];
protected System.Web.UI.HtmlControls.HtmlGenericControl inde;
public string[] min=new string[5];
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection con = new SqlConnection("server=.;database=Systen;user id=sa;password=;");
string str_top="select top 5 category from product_category_table where grade=1 and changes=0 order by bys";
SqlDataAdapter da = new SqlDataAdapter(str_top, con);
StringBuilder sb_slist=new StringBuilder();
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
{
string str_Temp_Pic = "";
string str_Temp_Link = "";
string str_info = "select pr_image,pro_url from product_image where pro_type='" + ds.Tables[0].Rows[m][0].ToString() + "'";
SqlDataAdapter da1 = new SqlDataAdapter(str_info, con)
sb_slist.Append("<td align=\"center\" width=\"160\">");
sb_slist.Append(ds.Tables[0].Rows[m][0].ToString());
sb_slist.Append("<td>");
DataSet ds1 = new DataSet();
da1.Fill(ds1);
if (ds1.Tables[0].Rows.Count > 0)
{
for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)
{
str_Temp_Pic+="webupload/"+ds1.Tables[0].Rows[n][0].ToString() + "|";
str_Temp_Link += ds1.Tables[0].Rows[n][1].ToString() + "|";
//str_Temp_cname += ds.Tables[0].Rows[m][0].ToString() + "|";
}
}
pic[m] = str_Temp_Pic.Substring(0,str_Temp_Pic.Length - 1);
link[m] = str_Temp_Link.Substring(0, str_Temp_Link.Length - 1);
}
}
this.inde.InnerHtml=sb_slist.ToString();
}
为什么会报一个长度不能小于 0。参数名: length
SqlConnection con = new SqlConnection("server=.;database=Systen;user id=sa;password=;");
con.Open();
string str_top="select top 5 category from product_category_table where grade=1 and changes=0 order by bys";
SqlDataAdapter da = new SqlDataAdapter(str_top, con);
StringBuilder sb_slist=new StringBuilder();
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
{
string str_Temp_Pic = "";
string str_Temp_Link = "";
string str_info = "select pr_image,pro_url from product_image where pro_type='" + ds.Tables[0].Rows[m][0].ToString() + "'";
SqlDataAdapter da1 = new SqlDataAdapter(str_info, con)
sb_slist.Append(" <td align=\"center\" width=\"160\">");
sb_slist.Append(ds.Tables[0].Rows[m][0].ToString());
sb_slist.Append(" <td>");
DataSet ds1 = new DataSet();
da1.Fill(ds1);
if (ds1.Tables[0].Rows.Count > 0)
{
for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)
{
str_Temp_Pic+="webupload/"+ds1.Tables[0].Rows[n][0].ToString() + " ¦";
str_Temp_Link += ds1.Tables[0].Rows[n][1].ToString() + " ¦";
//str_Temp_cname += ds.Tables[0].Rows[m][0].ToString() + " ¦";
}
}
pic[m] = str_Temp_Pic.Substring(0,str_Temp_Pic.Length - 1);
link[m] = str_Temp_Link.Substring(0, str_Temp_Link.Length - 1);
}
}
this.inde.InnerHtml=sb_slist.ToString();
}
建议加个判断,
pic[m] = str_Temp_Pic.Length>0?str_Temp_Pic.Substring(0,str_Temp_Pic.Length - 1):"";
link[m] = str_Temp_Link.Length>0?str_Temp_Link.Substring(0, str_Temp_Link.Length - 1):"";