Results 1 to 6 of 6

Thread: Visual Basic

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    31

    Visual Basic

    I am trying to make a form that user can login to fill and not register, only admin can register. When the form is filled out I want it to store the data in the sql server and also when admin login they can be able to click and view the sumbitted information. Can some help me here?
    Last edited by sk19; Aug 11th, 2017 at 09:57 AM.

  2. #2
    Hyperactive Member Mike Storm's Avatar
    Join Date
    Jun 2017
    Location
    Belgium
    Posts
    425

    Re: Visual Basic

    Using the info from you project on your previus thread, easyest way would be adding a column to the users table named exemple (ActiveUser) sql datatype "bit".
    Let the users do its registration as it was doing on the previus thread and add a form that the admin uses to perform a query to the users table to get newly incript users.

    Query should be something like this:

    SELECT ColumnName1, ColumnName2, ColumnName3, ....., ActiveUser FROM users_table WHERE ActiveUser = FALSE

    That can also be done on SQLSERVER by creating a View with the sqlcode as above, and then insted of loading a table you load a view.

    Other option will be having a separated table to inscriptions with a triger that when admin activates the user it copies it to the user main table.

    You need to do a litle bit of thinking and reading there.

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Re: Visual Basic

    The first requirement is to perform a Select statement to check if an admin is logging in paired with an Insert statement to insert the data (assuming that the admin didn't log in). The second requirement is to perform a Select statement to return all rows.

    Assuming that your database schema looks something like this: https://app.genmymodel.com/edit/_sbI...eeEVMtrU1Znfg#

    Then you could use the following code:
    Code:
    Private Function IsAdmin(ByVal username As String, ByVal password As String) As Boolean
        'Declare the object to return
        Dim admin As Boolean = False
    
        'Declare the connection object
        Dim con As OleDbConnection
    
        'Wrap code in Try/Catch
        Try
            'Set the connection object to a new instance
            'TODO: Change "My Connection String Here" with a valid connection string
            con = New OleDbConnection("My Connection String Here")
    
            'Create a new instance of the command object
            Using cmd As OleDbCommand = New OleDbCommand("SELECT FIRST([isAdmin]) FROM [users] WHERE [username]=@user AND [password]=@pass;", con)
                'Parameterize the query
                With cmd.Parameters
                    .AddWithValue("@user", username)
                    .AddWithValue("@pass", password)
                End With
    
                'Open the connection
                con.Open()
    
                'Use ExecuteScalar to return a single value
                admin = Convert.ToBoolean(cmd.ExecuteScalar())
    
                'Close the connection
                con.Close()
            End Using
        Catch ex As Exception
            'Display the error
            Console.WriteLine(ex.Message)
        Finally
            'Check if the connection object was initialized
            If con IsNot Nothing Then
                If con.State = ConnectionState.Open Then
                    'Close the connection if it was left open(exception thrown)
                    con.Close()
                End If
    
                'Dispose of the connection object
                con.Dispose()
            End If
        End Try
    
        'Return the admin status
        Return admin
    End Function
    
    Private Sub InsertData(ByVal firstName As String, ByVal lastName As String, ByVal username As String, ByVal password As String)
        'Declare the connection object
        Dim con As OleDbConnection
    
        'Wrap code in Try/Catch
        Try
            'Set the connection object to a new instance
            'TODO: Change "My Connection String Here" with a valid connection string
            con = New OleDbConnection("My Connection String Here")
    
            'Create a new instance of the command object
            Using cmd As OleDbCommand = New OleDbCommand("INSERT INTO [users] ([firstName], [lastName], [username], [password], [isAdmin] VALUES (@first, @last, @user, @pass, @admin);", con)
                'Parameterize the query
                With cmd.Parameters
                    .AddWithValue("@first", firstName)
                    .AddWithValue("@last", lastName)
                    .AddWithValue("@user", username)
                    .AddWithValue("@pass", password)
                    .AddWithValue("@admin", False)
                End With
    
                'Open the connection
                con.Open()
    
                'Use ExecuteNonQuery to insert the row
                cmd.ExecuteNonQuery()
    
                'Close the connection
                con.Close()
            End Using
        Catch ex As Exception
            'Display the error
            Console.WriteLine(ex.Message)
        Finally
            'Check if the connection object was initialized
            If con IsNot Nothing Then
                If con.State = ConnectionState.Open Then
                    'Close the connection if it was left open(exception thrown)
                    con.Close()
                End If
    
                'Dispose of the connection object
                con.Dispose()
            End If
        End Try
    End Sub
    
    Private Function ReturnAllRows() As DataTable
        'Declare the object to return
        Dim dt As DataTable
    
        'Declare the connection object
        Dim con As OleDbConnection
    
        'Wrap code in Try/Catch
        Try
            'Set the connection object to a new instance
            'TODO: Change "My Connection String Here" with a valid connection string
            con = New OleDbConnection("My Connection String Here")
    
            'Create a new instance of the command object
            Using cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [users];", con)
                'Open the connection
                con.Open()
    
                'Use ExecuteReader to fill the DataTable
                Using reader As OleDbDataReader = cmd.ExecuteReader()
                    dt = New DataTable()
                    dt.Load(reader)
                End Using
    
                'Close the connection
                con.Close()
            End Using
        Catch ex As Exception
            'Display the error
            Console.WriteLine(ex.Message)
        Finally
            'Check if the connection object was initialized
            If con IsNot Nothing Then
                If con.State = ConnectionState.Open Then
                    'Close the connection if it was left open(exception thrown)
                    con.Close()
                End If
    
                'Dispose of the connection object
                con.Dispose()
            End If
        End Try
    
        'Return the DataTable
        Return dt
    End Function
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    31

    Re: Visual Basic

    Got that. But I want to be able to see the submitted information when login into the application. How will display that?

  5. #5
    Hyperactive Member Mike Storm's Avatar
    Join Date
    Jun 2017
    Location
    Belgium
    Posts
    425

    Re: Visual Basic

    And by the way, next time you start a thread use a apropriated description.
    Visual basic does not describes your problem.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    31

    Re: Visual Basic

    [url]https:/ject
    Last edited by sk19; Sep 21st, 2017 at 11:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width