【发布时间】:2018-10-23 23:29:44
【问题描述】:
我想知道将数据库中的行列下拉列表提供到下拉列表 Web 表单控件中的最佳方法是什么。我从 Page_Load 函数开始,并希望在我的 aspx 页面上的下拉列表加载页面时列表数据可用。在这个场景中,我的下拉 ID 是 DropDownList1。如何添加到当前代码中?
SqlConnection myConnection = ConfigManager.GetConnection(ConnectionTarget.TestModule);
SqlCommand myCommand = new SqlCommand("SELECT DISTINCT [col1]"
+ ",[col2]"
+ ",[col3]"
+ ",[col4]"
+ "FROM[db].[dbo].[table]"
+ "ORDER BY col1", myConnection);
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
【问题讨论】:
标签: webforms