none
a login form for visual basic 2010 using acces

    Question

  • hey ive made a code that will read a database but i need a button that will "Create an account" and save the details into the access database so it can log in. could someone give me the code or preferably link me to a site which can give me an idea: here is my code so far

    Imports System.Data.OleDb
    Public Class Form1
    
        Private Property Form1 As Object
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
        ' OK button   
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source='C:\Users\jacob\Documents\myDB.mdb'")
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM userDetails WHERE userID = '" & userNameTextBox.Text & "' AND password = '" & passwordTextBox.Text & "' AND role = '" & ComboBox1.Text & "' ", con)
    
            con.Open()
            Dim sdr As OleDbDataReader = cmd.ExecuteReader()
            ' If the record can be queried, Pass verification and open another form.   
            If (sdr.Read() = True) Then
                MessageBox.Show("The user is valid!")
                Dim Form1 As New Form
                Me.Close()
            Else
                MessageBox.Show("you got it wrong")
            End If
        End Sub
    
        ' Cancel button   
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
            Me.Close()
    
        End Sub
    
    End Class
    

    Wednesday, June 06, 2012 5:31 AM

All replies

  • Hello jacobase,

    hey ive made a code that will read a database but i need a button that will "Create an account" and save the details into the access database so it can log in. could someone give me the code or preferably link me to a site which can give me an idea: here is my code so far

    Imports System.Data.OleDb
    Public Class Form1
    
        Private Property Form1 As Object
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
        ' OK button   
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source='C:\Users\jacob\Documents\myDB.mdb'")
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM userDetails WHERE userID = '" & userNameTextBox.Text & "' AND password = '" & passwordTextBox.Text & "' AND role = '" & ComboBox1.Text & "' ", con)
    
            con.Open()
            Dim sdr As OleDbDataReader = cmd.ExecuteReader()
            ' If the record can be queried, Pass verification and open another form.   
            If (sdr.Read() = True) Then
                MessageBox.Show("The user is valid!")
                Dim Form1 As New Form
                Me.Close()
            Else
                MessageBox.Show("you got it wrong")
            End If
        End Sub
    
        ' Cancel button   
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
            Me.Close()
    
        End Sub
    
    End Class

    follow those sample

    http://www.youtube.com/watch?v=_Kdr_L_DFOI&feature=related

    http://www.developerfusion.com/code/5040/login-form/

    Regards.


    • Proposed as answer by mattiasrk Wednesday, June 06, 2012 1:19 PM
    Wednesday, June 06, 2012 5:45 AM
  • ive made the log in form and everything it works easyly but the problem is that i need to make a button that says create account and when you click it, you enter a username and password and it will make a record in the access database. at the moment the way ive made the login form is that i make a user id and password and visual basic reads the database and says the user is valid or not valid. but like i said i need it to create a record in the database

    Wednesday, June 06, 2012 5:55 AM
  • Password is a keyword so it has to be inside square brackets. [password]

    Better is to change it in the database as column because for sure you will sooner or later become in trouble.

    Also use parameters in your select.

    See here a simple sample on our website.

    http://www.vb-tips.com/SQLParameters.aspx

    Know that for OleDB which you are using the parameternames are not imported, they have to be added in the sequence as used in the select.


    Success
    Cor

    Wednesday, June 06, 2012 8:12 AM
  • ive managed to find a way to save stuff to a database hopefully how ever i got 2 errors

    Dim sqlinsert AsString= "insert into tbllogindetails (userID, password, role) "_

                                      "VALUES ('"& userID.text & "', '" & password.text & "', '" & rolebox1.text &"')"

    error is end of statement expected and

    trans = connection.BeginTransaction()

                IsolationLevel.readcommited()
    readcommited is not a member of 'system.data.isolationlevel'

    my full code is

    Imports System.Data
    Public Class Form2
    
        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub saverecord(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddRecord.Click
            Dim connection As OleDb.OleDbConnection
            Dim command As OleDb.OleDbCommand
            Dim trans As OleDb.OleDbTransaction
    
            Dim dbpath As String = "c:\users\jacob\documents\myDb.mdb"
    
            Dim connstr As String = "provider=microsoft.ace.oledb.4.0;" _
                                    & "data source=" & dbpath & "; persist security info = false;"
    
            Dim sqlinsert As String = "insert into tbllogindetails (userID, password, role) " _
                                      "VALUES ('"& userID.text & "', '" & password.text & "', '" & rolebox1.text &"')"
    
            Try
                connection = New OleDb.OleDbConnection(connstr)
    
                If connection.State = ConnectionState.Open Then
                    connection.Close()
                End If
    
                trans = connection.BeginTransaction()
                IsolationLevel.readcommited()
    
                command = New OleDb.OleDbCommand(sqlinsert, connection, trans)
    
                trans.Commit()
    
            Catch ex As Exception
    
            End Try
    
    
        End Sub
    
        Private Function sqlinsert() As Object
            Throw New NotImplementedException
        End Function
    
    End Class

    Wednesday, June 06, 2012 11:17 AM
  • Hello jacobace,

    ive made the log in form and everything it works easyly but the problem is that i need to make a button that says create account and when you click it, you enter a username and password and it will make a record in the access database. at the moment the way ive made the login form is that i make a user id and password and visual basic reads the database and says the user is valid or not valid. but like i said i need it to create a record in the database

    follow this example, performs the insert, update a user name and password, the difference lies in the fact that uses SqlCompact and Access, you can take as example the code and implement it in your project. You simply replace the namespace with SQLCE OleDb for Access.

    http://code.msdn.microsoft.com/vstudio/Esempio-applicazione-dati-70387089

    Regards.


    • Proposed as answer by mattiasrk Wednesday, June 06, 2012 1:19 PM
    Wednesday, June 06, 2012 11:24 AM
  •  can only read english i cannot read 3/4 of that code
    also would i be able to add 1 of you on skype or xbox live or something?
    Wednesday, June 06, 2012 11:57 AM
  • Hello jacobace,

     can only read english i cannot read 3/4 of that code
    also would i be able to add 1 of you on skype or xbox live or something?

    Comment on this page you have the code in English,

    http://code.msdn.microsoft.com/vstudio/Esempio-applicazione-dati-70387089/view/SourceCode#content

    even if it's C # to translate the code from VisualBasic to C # you can use this tool

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    soon as possible and weather permitting will publish an example.

    Regards. 


    Wednesday, June 06, 2012 5:40 PM
  • Hi Jacobace,

    Welcome to the MSDN forum.

    Here is a sample in OleDbConnection.BeginTransaction Method (I have short it). And it will help you cover the issue.

    Using connection As New OleDbConnection(connectionString)
            Dim command As New OleDbCommand()
            Dim transaction As OleDbTransaction
            command.Connection = connection
            Try
                connection.Open()
                transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)
                command.Connection = connection
                command.Transaction = transaction
                command.CommandText = _
                    "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
                command.ExecuteNonQuery()
                transaction.Commit()
            Catch ex As Exception
                Console.WriteLine(ex.Message)
                ' Try to rollback the transaction
            End Try
        End Using

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, June 07, 2012 3:27 AM
    Moderator
  • hey about my login form i have 3 boxes 1 textbox for userID 1 textbox for password and 1 listbox for role like S for student or R or something else but is there a way where i can make i can make it soo that people r forced to pick s or r because if you click on the listbox you can actually type in whatever you want id prefere you couldnt pick anything but s or r but if you can make anything and then it says u can only use s or r. ive tried searching it into google but i just got other stuff.
    also can someone link me to a site or give me the code to block out a password like instead of the password being jacob1996 it would appear as ******** also if someone could link me to some kind of cinema movie booking seat system,

    i know ive asked alot from you guys but my class has only being studying coding for bout 1 month and then she gives an assignment like this i think it is unfair to be honest

    Saturday, June 09, 2012 8:11 AM
  •      " 1 listbox for role like S for student or R"

         I just created a listbox with S and R in it. I can't type into it ("because if you click on the listbox you can actually type in whatever you want") like you said you could. I can highlight either the S or the R but not type into the actual listbox. And I can only highlight one of them. So I suppose you could use a messagebox to display that one or the other has to be highlighted before the user can move to the next step.

         Are you sure you aren't talking about a textbox and not a listbox?


    You've taught me everything I know but not everything you know.


    Saturday, June 09, 2012 9:01 AM
  • o wait shit i was using a combo box >.< fuck im dumb

    Saturday, June 09, 2012 9:59 AM
  • Hi Jacobace,

    Can I get the meaning of finishing this thread?

    I look forward your reply.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 12, 2012 8:06 AM
    Moderator
  • im sorry mark what do u mean by what u said im sorry im new to this website
    Thursday, June 14, 2012 2:16 PM
  • Hi Jacobace,

    Thanks for your reply.

    I just want to know whether you have solved your original issue with help of members. If yes, please mark the helpful replies as answer. It will help other members who has similar issue with you find the solution easier.

    Sorry for any incontinences and have a nice day.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 15, 2012 7:58 AM
    Moderator