财产'项目'是'只读''

时间:2013-12-11 10:10:08

标签: vb.net visual-studio-2010 visual-studio

运行代码时出现上述错误。我认为这是因为DataReader是只读的,因此无法修改该值。作为一个新用户仍然掌握来自php / mysql背景的vb.Net,有人可以告诉我正确的编码方式或提供替代方法。非常感谢

     While dr.Read()
        If dr.HasRows Then

          lvRequests.Items.Add((dr(0)).ToString()).UseItemStyleForSubItems = False
          lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(CDate(dr(5)).ToShortDateString())
          lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(1).ToString())
          With lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(3).ToString())
             If dr(3) Is "D" Then    
                dr(3) = "destroyed"  <--- ERROR

             ElseIf dr(3) Is "O" Then
                dr(3) = "out"        <--- ERROR

             End If

           End With

           lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(9).ToString())

           lvcount += 1
         End If

    End While

1 个答案:

答案 0 :(得分:1)

您无法更改datareader的值。而不是这个

      With lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(3).ToString())
         If dr(3) Is "D" Then    
            dr(3) = "destroyed"  <--- ERROR

         ElseIf dr(3) Is "O" Then
            dr(3) = "out"        <--- ERROR

         End If

       End With

做这样的事情

         If dr(3).ToString() = "D" Then    
            lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add("destroyed")

         ElseIf dr(3).ToString = "O" Then
            lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add("out")

         Else

            lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(3).ToString())
         End If