出现“列不属于表”的错误,求高手解答。
这阵子系统出现出现“列不属于表”的错误,通过追踪发现,比如我查A表的记录,偶尔会返回给我B表的记录。这个通过遍历返回的DataTable的Column发现的。下面是追踪的代码,不知道有没有人知道为什么。public string html = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
html = string.Empty;
html = GetHtml();
}
protected string GetHtml()
{
string line = "<br/>";
StringBuilder sb = new StringBuilder();
using (SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["SqlConnString"].ToString()))
{
Conn.Open();
string sql = "Select * From Pro_Brand Order By Brand_Name Desc";
using (SqlDataAdapter Sda = new SqlDataAdapter("Select * From Pro_Brand Order By Brand_Name Desc", Conn))
{
using (DataTable Dt = new DataTable())
{
Sda.Fill(Dt);
sb.Append("sql语句:" + sql + line);
sb.Append("SqlDataAdapter.SelectCommand.CommandText:" + Sda.SelectCommand.CommandText + line);
sb.Append("DataTable.Columns.Count:" + Dt.Columns.Count + line);
//输出列名
for (int i = 0; i < Dt.Columns.Count; i++)
{
sb.Append("DataTable.Columns[" + i + "].ColumnName:" + Dt.Columns[i].ColumnName + line);
}
//输出列值
for (int i = 0; i < Dt.Rows.Count; i++)
{
sb.Append("DataTable.Rows[" + i + "] value:" + Dt.Rows[i][0] + line);
}
}
}
}
return sb.ToString();
}
C# asp.net ADO.NET --------------------编程问答-------------------- http://blog.csdn.net/sollion/article/details/5753825
补充:.NET技术 , ASP.NET