vb.net在数据集中查找具有列值的行 [英] vb.net finding a row in a dataset with a column value

查看:144
本文介绍了vb.net在数据集中查找具有列值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在数据集中找到具有列值的行.该列是布尔数据类型.

I am trying to find a row in a dataset with a column value. The column is a boolean data type.

 Dim foundRows() As Data.DataRow
foundRows = dsans.Tables(0).Select("correct_ans = 'true'")
               Dim j As Integer
               Dim iRowIndex As Integer
               For j = 0 To dtans.Rows.Count - 1
                   If dtans.Rows(j).Equals(foundRows) Then
                       iRowIndex = j
                       Exit For
                   End If
               Next
               answer = dtans.Rows(iRowIndex).Item(1)


每次返回第一行时都不会检查条件
correct_ans = ''true''. select语句有什么问题吗?


Everytime it returns the first row.It is not checking the condition
correct_ans = ''true''. Is anything wrong in the select statement?

推荐答案

如果是布尔值,只需尝试一下即可.
If it is boolean, simply try this.
dsans.Tables(0).Select("correct_ans") ' or "NOT correct_ans"


您的比较是针对字符串类型,而不是布尔值.

一开始发现问题时,我真的很想念这部分.


Your comparison is for string types, not for boolean.

I really missed this part when I found problem at first.

For j = 0 To dtans.Rows.Count - 1
  If dtans.Rows(j).Equals(foundRows) Then
    iRowIndex = j
    Exit For
  End If
Next


foundRowsDataRow的数组.您要尝试的是将DataRow等同于它.


foundRows is array of DataRow. What you are trying to is to equate DataRow to it.


correct_ans字段的类型是什么.是布尔值还是字符串?

您在此处进行的比较本质上是一个字符串,因此,如果类型不匹配,则不会返回任何结果.
What is the type of the correct_ans field. Is it boolean or string?

The comparison you are doing here is essentially a string so there are no results returned if the types are not matching.


这篇关于vb.net在数据集中查找具有列值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆