locked
How to create login form in v.b net using sql local database(.mdf) RRS feed

  • Question

  • please i need urgent help in building my application.

    the application is a church management system,with login page but i want to use a local generated database in vb.net(not third party mysql or sql sever).

    i have created the database with the login table called 'USER PROFILE with have two columns mainly 

    1.USERNAME

    2. PASSWORD

    this my connection string:Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\LIBRARY\ACADEMIC & EDUCATION\PROJECTS\I.T\VISUAL BASIC\A.C.C.M.S\A.C.C.M.S\LOCAL DATABASE FOR ACCMS.mdf;Integrated Security=True

    and on my login form the text boxes used in getting the USERNAME and PASSWORD texts are username1 and password1 textboxes.

    plz i want the code to help me connect my form to the sql local database so i can configure the user logging in to gain access to the main form. 


    Sunday, February 11, 2018 9:09 PM

All replies

  • This forum is for Visual Studio IDE, as the issue is more related to VB.net developing, I will it to corresponding forum for you to get a better answer.

    Your understanding and cooperation will be grateful.

     

    Regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 12, 2018 5:15 AM
  • Hi NANA,

    If you want to create login form use Local database, you can take a look the following code. I useSqlCommand.ExecuteScalar Method ()  to return the row count.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.Text.Length <= 0 Then
                MessageBox.Show("Please enter Username!")
            ElseIf TextBox2.Text.Length <= 0 Then
                MessageBox.Show("Please enter Password!")
            End If
            Dim str As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\CherrySample\Demo(vb.net)\Test2\Database1.mdf;Integrated Security=True"
            Dim sql As String = "select count(*) from USERPROFILE where Username=@Username and Password=@Password"
            Using Conn As New SqlConnection(str)
                Using cmd As New SqlCommand(sql, Conn)
                    Conn.Open()
                    cmd.Parameters.AddWithValue("@Username", TextBox1.Text)
                    cmd.Parameters.AddWithValue("@Password", TextBox2.Text)
                    Dim value = cmd.ExecuteScalar()
                    If value > 0 Then
                        MessageBox.Show("Login sucessfully!")
                    End If
                End Using
    
            End Using
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 12, 2018 5:56 AM