【发布时间】:2014-09-23 21:15:04
【问题描述】:
我有一个列表框,在加载页面时,我想选择数据库中的选项/选项。自从我对列表框做任何事情以来已经有一段时间了,所以我对如何修复我的 GetClassification 函数的代码有点困惑,这就是为了做到这一点。目前,它只在列表框中选择一个值,而不管供应商 id 是否与多个关联。
这是GetClassification函数的代码:
protected void GetClassification(int VendorId)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
{
SqlCommand cmd = new SqlCommand("SELECT uidClassification FROM Baird_Vendors_Extension WHERE uidVendor = @VendorId", cn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new SqlParameter("@VendorId", VendorId));
cn.Open();
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
vendorType.SelectedValue =reader["uidClassification"].ToString();
}
}
}
}
【问题讨论】:
-
您不需要
@ClassId,因为您没有在SqlCommand中声明此参数。 -
我正在使用 ASP.NET。