lutonian
Member
- Joined
- Apr 5, 2013
- Messages
- 16
- Programming Experience
- Beginner
Hello all,
I have connect a project with an access database. That database has a table with logins.
What I need it is that if the username is into the database.column then hide a button. I have use two methods but never works.
I have make this code in vb.net, using both methods and do not work any of them.
Any one can tell me what it is happing or how to do it?
Thank you.
Jose Luis.
I have connect a project with an access database. That database has a table with logins.
What I need it is that if the username is into the database.column then hide a button. I have use two methods but never works.
VB.NET:
If RecordCount = 1 Then
DBaccbt.Hide()
End If
If Environment.UserName IsNot cmndTL Then
DBaccbt.Hide()
End If
I have make this code in vb.net, using both methods and do not work any of them.
VB.NET:
'Database connection and commands.
Dim DBConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\sfs.corp\Projects\ICT\SERVICEDESK_SHARE\SD_Only\Tools\JLTool\DataBase\LOGIN.accdb"
Public Conex As New OleDbConnection(DBConnStr)
Dim cmndTL As OleDbCommand = New OleDbCommand("select count(*) from TL_LoginTB WHERE LOGINTL = @Username", Conex)
'Dim UserFoundCountTL As Integer = CInt(cmndTL.ExecuteScalar())
Dim RecordCount As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RecordCount = CInt(cmndTL.ExecuteScalar())
cmndTL.Parameters.AddWithValue("@Username", Environment.UserName)
Try
Conex.Open()
Catch
MsgBox("Data Base cannot be found." + vbNewLine + "Please contact to a L2", MsgBoxStyle.OkOnly)
End Try
'TESTING... IF THE USERNAME IS ON DATABASE. IF NOT HIDE DB BUTTON AND TABCONTROL
'Create another application for TL in case L1
If RecordCount = 1 Then
DBaccbt.Hide()
'ElseIf UserFoundCountL1 = 1 Then
' DBaccbt.Hide()
' Me.TabControl.TabPages.Remove(QualityTab)
End If
'ANOTHER METHOD USED
'If Environment.UserName IsNot cmndTL Then
' DBaccbt.Hide()
' End If
Conex.Close()
Any one can tell me what it is happing or how to do it?
Thank you.
Jose Luis.