//combox绑定数据库里的内容,wpf要用蓝色字体的就可以了,注意要修改DisplayMemberPath/DisplayMember的属性
string con = "Server=localhost;
database=fooddatabase;uid=sa;password=123";
SqlConnection conn = new SqlConnection(con);
conn.Open();
string sql = "select username from examineinfor";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
conn.Close();
DataView dv = new DataView();
dv = dt.DefaultView;
comboBox1.ItemsSource = dv;
comboBox1.DisplayMemberPath = "username";