在编程时我是新手,我只是对开始感兴趣。 我已经创建了一个简单的asp web项目,并且包含多个网页,我有下拉列表。
我可以创建一个使用数据集从我的数据库中选择项目标题的类,这一切都运行正常。我的问题是如何从不同的网页调用此类将数据绑定到我的下拉列表?
以下是我从数据库中提取所需数据的代码
public void cmbProject()
{
using (SqlConnection oConn = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ToString()))
{
string sql = "select pr.ProjectID, lo.UserName, " +
"pr.Title " +
"from Project pr " +
"inner join ProjectUsers pu on pu.ProjectID = pr.ProjectID " +
"inner join Users us on us.UserID = pu.UserID " +
"inner join Login lo on lo.UserID = us.UserID " +
"where lo.UserName like '%daniel_23%'";
try
{
oConn.Open();
//fill drop down list with project listings
SqlCommand cmd = new SqlCommand(sql, oConn);
SqlDataReader reader = cmd.ExecuteReader();
oConn.Close();
}
catch (Exception)
{
throw;
}
}
}