Please i'm developing an application with vb.net and mysql. I want to add additional users to the application but with different access levels. this is my original code

sql = "select username, password from users where (username = '" & UsernameTextBox.Text & "') and (password = '" & PasswordTextBox.Text & "')"
        conn.ConnectionString = "server=localhost;" _
                            & "database=cargomanager;" _
                            & "userid=root;" _
                            & "password=admin;"


        Try
            conn.Open()
        Catch myerror As MySqlException
            MsgBox("sorry connection failed")
        End Try
        command.Connection = conn
        command.CommandText = Sql
        adapter.SelectCommand = command
        Dim mydata As MySqlDataReader
        mydata = command.ExecuteReader()
        

        If mydata.HasRows = 0 Then
            MsgBox("Invalid username/password", MsgBoxStyle.Information)
        Else
            Form1.Show()
            Me.Close()
        End If.

If i add a third parameter named level to the sql statement, how do i determine which form shows???

You would add a level field to the users table and use a switch/case or a series of if statements to check what access the user has. Once you determine that, send them off to the appropriate form. I would create a separate query with the username and level to check access.

There are several ways you can accomplish this. You can either define there security through coding as mentioned above and then handle it in the project depending on the users level or you can define it right in Sql Server itself by assigning the proper permissions per table for each of the users.

I already have a field called level in the database. My problem comes from the

mydata.hasrows

this returns true or false so there is no way i know of to read the level.
I know its going to take a couple of ifs statement.. its just how to read the values i havnt figured out yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.