我需要知道已经 用户是否具有权限 .. 列必须检查。 ..我使用以下代码...它不工作...请帮助我.. 我的数据网格名称 DGV1 在我的旧版本中他们正在使用列表视图.. bt我必须使用datagrid ..我还在我的数据网格名称中添加了 datagridcheckbox 列 SEL 所以,如果已经有用户权限,则已经选中了复选框.. soo如果用户取消选中那个... 权限将被撤销 ..撤销权限是工作正常..但是我无法显示有所需公司授权的用户列表..
Private Sub getuserlist()
strCon = "Server=PTMCPC25;Database=CSSYSDB;uid=sa;pwd=Sqlsvr12"
sqlCon = New SqlClient.SqlConnection(strCon)
sqlCon.Open()
coid = getcoid()
Dim i, j, k As Integer
Dim aruid(100) As String
Dim count As Integer
Dim rs4 As SqlClient.SqlDataReader
Dim cmd As New SqlClient.SqlCommand("SELECT * from sy30102 order by uid ", sqlCon)
j = 0
' count = New DGV1.BindingContext(DGV1.DataSource, DGV1.DataMember).Count
rs4 = cmd.ExecuteReader
If rs4.HasRows Then
Do While rs4.Read
count = count + 1
aruid(j) = rs4("uid")
j = j + 1
Loop
rs4.Close()
End If
rs4.Close()
ds = New DataSet
Dim da As SqlDataAdapter
da = New SqlDataAdapter("Select uid 'USER ID',uname 'USER NAME' from sy30102 order by uid", sqlCon)
ds.Clear()
da.Fill(ds, "ConnToSqlDrp")
If ds Is Nothing = True Then
Exit Sub
Else
da.Fill(ds)
DGV1.DataSource = ds.Tables(0)
End If
k = count - 1
For i = 0 To k
Dim rs1 As SqlClient.SqlDataReader
Dim cmd2 As New SqlClient.SqlCommand("Select * from sy30103 where COYID = '" & coid & "' and UID = '" & aruid(i) & "'", sqlCon1)
Try
rs1 = cmd2.ExecuteReader
If rs1.HasRows Then
ds.Tables(0).Rows(i).Item("SEL").value = True
'Next
End If
rs1.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
Next
closecon()
End Sub
答案 0 :(得分:0)
没有人回复......我的自我发现他已经解决了......
Private Sub getuserlist()
Try
If cmbcname.Text <> "" Then
For Each ROW As DataGridViewRow In DGV1.Rows
Dim rs1 As SqlClient.SqlDataReader
Dim cmd2 As New SqlClient.SqlCommand("Select * from sy30103 where COYID = '" & cmbcname.SelectedValue & "' and UID = '" & ROW.Cells("USER ID").Value.ToString & "'", sqlCon)
Try
rs1 = cmd2.ExecuteReader
If rs1.HasRows Then
'For Each row As DataGridViewRow In DGV1.Rows
' l = DGV1.CurrentRow.Index
'row.Cells("Column1").Value = True
ROW.Cells("SEL").Value = True
Else
ROW.Cells("SEL").Value = False
'Next
End If
rs1.Close()
'rs1 = cmd2.ExecuteReader
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
Next
End If
Catch ex As Exception
End Try
'closecon()
End Sub