Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

Problem with username and access database

$
0
0
Hello all,

I have a problem with this code, I created an application with severals programs inside. Some of those programs are banned to some people, those people are clasified into an MS access database.

What I want to do is that in case the username "Environment.UserName" is into the database.table hide some buttons and tabpages.

I dont have any error show in this code, just does not work, I mean the button still appear.

I have created the code in a button so you see better in case there is any error.

Code:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  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"
  Dim Conex As New OleDbConnection(DBConnStr)
  Dim cmndTL As OleDbCommand = New OleDbCommand("select count(*) from TL_LoginTB WHERE LOGINTL = @Username", Conex)
  Dim RecordCount As Integer
 
  cmndTL.Parameters.AddWithValue("@Username", Environment.UserName)
 
  Try
    'Try to open the Database and Execute the Command
    Conex.Open()
    RecordCount = CInt(cmndTL.ExecuteScalar)
    If RecordCount > 0 Then
      'There is a valid User so do something
    End If
  Catch ex As Exception
    'If something fails then display what the Error Message is
    MsgBox(ex.Message)
  Finally
    'Regardless of Success or Failure always Close the database if it Opened Successfully
    If Conex.State = ConnectionState.Open Then
      Conex.Close()
    End If
  End Try
End Sub

Thank you,
Jose Luis,

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>