中易网

vb.net 索引超出范围

答案:1  悬赏:0  
解决时间 2021-04-28 02:50
  • 提问者网友:长安小才冯
  • 2021-04-27 20:20

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim conn As New SqlConnection("Data Source=20100319-2251\SQLEXPRESS;Initial Catalog=GJ;Integrated Security=True")
        Dim i, j As Long
        Dim str1, str2 As String
        Dim cmd, co As SqlCommand
        conn.Open()
        For i = 0 To ListBox1.Items.Count - 1
            str1 = "update 用户表 set 用户权限='管理员' where 用户名= '" & ListBox1.Items.Item(i).Text & "'"
            cmd = New SqlCommand(str1, conn)
            Dim objreader As SqlDataReader
            objreader = cmd.ExecuteReader

            objreader.Close()
        Next
        If ListBox2.Items.Count > 0 Then
            For j = 0 To ListBox1.Items.Count - 1
                str2 = "update 用户表 set 用户权限='普通用户' where 用户名= '" & ListBox2.Items.Item(j).Text & "'"
                co = New SqlCommand(str2, conn)
                Dim we As SqlDataReader
                we = co.ExecuteReader
                we.Close()
            Next

 

            conn.Close()
        End If
        Label1.Text = "权限修改成功!"
    End Sub

 

 

当ListBox2  剩下一条数据是  会发生错误!!

ListBox1 剩下一条数据没错误!

 str2 = "update 用户表 set 用户权限='普通用户' where 用户名= '" & ListBox2.Items.Item(j).Text & "'"
当ListBox2  剩下一条数据 运行错误是这句代码!!

请问是怎么回事!

最佳答案
  • 二级知识专家网友:伤口狠精致
  • 2021-04-27 21:27
    应该是listbox2
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息