数据库的表中,如果有多个列要现实,而对应的是ListBox控件,一般情况下,ListBox是单列显示的, 例如

 ListBox1.DataSource = dbcenter.accessGetDataSet(sql);
           ListBox1.DataTextField = "grade";
          ListBox1.DataValueField = "grade";
           ListBox1.DataBind();

多列显示怎么办呢,原来比较简单,就利用 ListBox的  ListBox1.Items.Add(ds.Tables[0].Rows[j]["数据列"]  的方法

conn.open(); 

DataSet ds=dbcenter .accessGetDataSet (sql);      

       int i = dbcenter.accessGetDataSet(sql).Tables[0].Rows.Count;   

          for (int j = 0; j < i; j++)         

    {      

       ListBox1.Items.Add(ds.Tables[0].Rows[j]["grade"].ToString()+"年级" + ds.Tables[0].Rows[j]["exam_subject"].ToString());    

            }

            conn.Close();  

       }

测试通过

相关文章:

  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-12-18
  • 2022-12-23
  • 2021-07-26
  • 2021-05-31
相关资源
相似解决方案