【发布时间】:2019-06-19 20:15:00
【问题描述】:
我正在创建一个表单,我必须将数据库中的数据显示到组合框中,我需要帮助来完成它,请
我已经尝试下载 MySql Server,但是它只支持到 Visual Studio 2017,我有 Visual Studio 2019
using (SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Code\C#\MyFirstUI\MyFirstUI\LOGIN.mdf;Integrated Security=True"))
{
try
{
string query = "select USERNAME from LOGIN";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds, "Username");
comboBox3.DisplayMember = "Userame";
comboBox3.DataSource = ds.Tables["Username"];
}
catch (Exception ex)
{
// write exception info to log or anything else
MessageBox.Show(ex.Message,"Error occured!");
}
}
我本来期望数据库中的数据,但是我没有得到任何输出
【问题讨论】:
-
comboBox3.DisplayMember = "Username";你错过了“n”。 -
哦,我去看看以后能不能用
-
遗憾的是,没有区别
-
好吧,使用调试器。在该 DataSource 行上停止并在程序停止时检查该 DataTable。
标签: c# combobox sqlconnection sqldataadapter