我有一个asp.net网站,我试图开发,我有一个问题从数据库中加载数据。它在C#WebForm应用程序中运行正常,我想知道我需要做什么才能使其在asp.net项目中正常工作,并将结果绑定到要从中选择的下拉列表。从asp.net内的数据库访问C#网站sitie
try
{
SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder
{
DataSource = "127.0.0.1",
InitialCatalog = "PIIMSDATA",
IntegratedSecurity = true
};
SqlConnection cs = new SqlConnection(connectionStringBuilder.ToString());
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Book1 Order by ID", cs);
}
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
//DropDownList2.DataSource = ds.Tables[0];
//DropDownList2.DataTextField = "ID";
//DropDownList2.DataValueField = "ID";
//DropDownList2.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + ex + "');", true);
//MessageBox.Show(ex.Message);
}
}
你的问题是什么? – Ash
我取消注释DropDownList代码后,它永远不会填充我的数据库结果 –
您是否收到某种错误?尝试逐行调试代码。 – Ash