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 剩下一条数据 运行错误是这句代码!!
请问是怎么回事!