c# Property Grid 下拉框中的值如何从数据库中取
我想让数据库中的值显示在下拉菜单中,可以随意选择,怎么做。没头绪呢我的数据库名称叫做fw_t_Sel_Img,那个字段叫做(也就是属性的名称)panel_idpublic...
我想让数据库中的值显示在下拉菜单中,可以随意选择,怎么做。没头绪呢我的数据库名称叫做 fw_t_Sel_Img , 那个字段叫做(也就是属性的名称)panel_id
public class TZ4Converter : StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
//下拉框元素集合
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[] {""});
}
//
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
怎么写SQL语句 展开
public class TZ4Converter : StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
//下拉框元素集合
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[] {""});
}
//
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
怎么写SQL语句 展开
2个回答
展开全部
List<int> dt = new List<int>();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True;User Instance=True";
conn.Open();
string selStr = "select panel_id from fw_t_Sel_Img";
SqlCommand cmd = new SqlCommand(selStr, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
dt.Add(reader.GetInt32(0));
}
this.DropDownList1.DataSource = dt;
this.DropDownList1.DataBind();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True;User Instance=True";
conn.Open();
string selStr = "select panel_id from fw_t_Sel_Img";
SqlCommand cmd = new SqlCommand(selStr, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
dt.Add(reader.GetInt32(0));
}
this.DropDownList1.DataSource = dt;
this.DropDownList1.DataBind();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询