public partial class DropDownList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dropdownticket();
}
}
string strsqlcon = ConfigurationManager.ConnectionStrings["sqlconn"].ConnectionString;
protected void dropdownticket()
{
try
{
SqlConnection sqlconn = new SqlConnection(strsqlcon);
SqlCommand cmd = new SqlCommand("SELECT * FROM SYS.databases", sqlconn);
sqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet sd = new DataSet();
sda.Fill(sd);
Dropdownlist1.DataSource = sd;
Dropdownlist1.DataTextField = "";
Dropdownlist1.DataValueField = "";
Dropdownlist1.DataBind();
Dropdownlist1.Items.Insert(0, new ListItem("--Select--", "0"));
sqlconn.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
在上面的代碼中,我無法在下拉列表中找到數據庫列表。想要將所有數據庫從SQL Server綁定到下拉列表(想要在下拉列表中列出所有數據庫)
親愛的,請解釋一下,意思是你想對所有數據庫在您的SQL Server在下拉列表中,然後當你要查詢的下拉列表中選擇數據庫,這個數據庫讓那麼我知道我會送你回答 – Developerzzz