【问题标题】:Gridview row count with condition [closed]带有条件的Gridview行计数[关闭]
【发布时间】:2015-08-22 16:56:30
【问题描述】:

I have a gridview which is bounded with a combobox and when an item in the combobox is selected the gridview shows the data.

我想知道 gridview 中 2 个标签中的男性和女性数量,但我找不到好的解决方案,请给我提示或代码?

【问题讨论】:

  • 请提供您目前拥有的相关代码,并告诉我们您遇到的问题。
  • @DeanOC:我刚刚发布了代码,请通过..
  • da1.Fill(ds).ToString() 是做什么的?
  • da1.Fill(ds)之后绑定dataGridView1.DataSource
  • @AmitKumarGhosh 当我从最后一行删除 Fill(ds) 部分时,它在标签“syste.data.oledb.oledbdataadaptor”中显示以下内容

标签: c# winforms datagridview


【解决方案1】:

您可能只需要这 3 行来满足您的要求,而不需要任何数据库操作。

    dataGridView1.DataSource = ds.Tables[0];
    lbltotalfemale.Text = ds.Tables[0].Select("Gender='female'")
                                      .Count().ToString();
    lbltotalmale.Text = ds.Tables[0].Select("Gender='male'")
                                    .Count().ToString();

希望这会有所帮助...

【讨论】:

  • 感谢它有效,但我需要 gridview 中的女性总数,这给出了该行的确切值!
  • @Vanest - 看看他随身携带的query1。它只返回一个计数。
  • 谢谢老兄!你拯救了我的一天..它工作得很好:-)
  • @Vanest - ds.Tables[0] 返回什么?
  • ds.Tables[0] 只不过是DataTable
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 2020-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多