/// <summary>
/// 绑定分类
/// </summary>
private void Bind_DropClassList()
{
DataView dv = this.GetList().Tables[0].DefaultView
if (dv != null &&dv.Count >0)
{
DataTable ddltable = new DataTable()
DataRow row = null
ddltable.Columns.Add("Name")
ddltable.Columns.Add("ID")
for (int i = 0i <dv.Counti++)
{
row = ddltable.NewRow()
row["ID"] = dv[i]["ID"].ToString()
row["Name"] = dv[i]["Name"].ToString()
ddltable.Rows.Add(row)
}
this.ddlClassID.DataSource = ddltable
this.ddlClassID.DataTextField = "Name"
this.ddlClassID.DataValueField = "ID"
this.ddlClassID.DataBind()
}
else
{
this.ddlClassID.Items.Clear()
ddlClassID.Items.Insert(0, new ListItem("暂无内容", ""))
}
}
public DataSet GetList()
{
StringBuilder strSql = new StringBuilder()
strSql.Append(" select ID,Name ")
strSql.Append(" FROM Product ")
DataSet ds = new DataSet()
try
{
connection.Open()
SqlDataAdapter command = new SqlDataAdapter(strSql, connection)
command.Fill(ds, "ds")
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message)
}
finally
{
connection.Close()
}
return ds
}
这个错误只可以是字段的错误啊,除此之外没有其它的情况会报错。好好检查下。出现这种错误一般是SQL语句的错误,很可能是SQL语句里用到的字段名称和数据库的表中使用的字段名称不一致.仔细检查检查SQL语句和数据库中的表,肯定能发现错误所在!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)