c# Property Grid 下拉框中的值如何从数据库中取

2025-05-14 20:07:17
推荐回答(1个)
回答(1):

List dt = new List();
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();