none
CREATE AND LOG IN RRS feed

  • Question

  • Please am new to visual basic, can someone teach me How To create a registration page and save to database and also sign in with details retrieved from the database
    Thursday, May 4, 2017 7:51 PM

All replies

  • These forums are not for testing but instead to assist with a task, lead them in the right direction or a problem, point to a better way or point out the issue.

    Any ways, your question is too high level, nothing mentioned about details from a database or the type of database.

    I could lead you down a path using Entity Framework, SqlClient, OleDb as core classes to work with data, from there are several classes to use to work with data.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, May 4, 2017 9:31 PM
    Moderator
  • Hi King,

    I'm not exactly what you want to do, but I do a sample about login and Register you can refer to.

    Imports System.Data.SqlClient
    
    Public Class Register
        Private Sub Register_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
        Private Sub Registerdate()
    
            Dim strConn As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C# and VB Support\Example(VB)\Demo\Database2.mdf;Integrated Security=True"
            Dim conn As New SqlConnection(strConn)
            conn.Open()
            Try
                Dim selectSql = "select * from test3 where UserName=@UserName and Password=@Password"
                Dim com As New SqlCommand(selectSql, conn)
                com.Parameters.AddWithValue("@UserName", TextBox2.Text)
                com.Parameters.AddWithValue("@Password", TextBox3.Text)
                Dim result As Integer = com.ExecuteNonQuery()
                If result = 1 Then
                    MessageBox.Show("UserName has registered!")
                    conn.Close()
                Else
                    Dim sql = "select Max(Id) as ID from test3"
                    Dim com1 As New SqlCommand(sql, conn)
                    Dim dt As New DataTable()
                    Try
                        Dim sda As New SqlDataAdapter(com1)
                        sda.Fill(dt)
                        Dim ID As Integer = dt(0)(0)
                        Dim sqlQuery As String = "insert into test3(Id,Name, username, Password,Types) values(@ID,@Name,@UserName,@Password,@Types)"
                        Using com2 As New SqlCommand(sqlQuery, conn)
                            Try
                                com2.Parameters.AddWithValue("@ID", ID + 1)
                                com2.Parameters.AddWithValue("@Name", TextBox1.Text)
                                com2.Parameters.AddWithValue("@UserName", TextBox2.Text)
                                com2.Parameters.AddWithValue("@Password", TextBox3.Text)
                                com2.Parameters.AddWithValue("@Types", ComboBox1.Text)
                                com2.ExecuteNonQuery()
                                conn.Close()
                                MessageBox.Show("Register successful!")
                            Catch ex As Exception
                                MessageBox.Show(ex.Message)
                            End Try
                        End Using
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
    
                End If
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
            End Try
    
    
        End Sub
        Private Sub LoginDate()
            Dim strConn As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C# and VB Support\Example(VB)\Demo\Database2.mdf;Integrated Security=True"
            Using conn As New SqlConnection(strConn)
                Dim selectSql = "select * from test3 where UserName=@UserName and Password=@Password"
                Using com As New SqlCommand(selectSql, conn)
                    Try
                        conn.Open()
                        com.Parameters.AddWithValue("@UserName", TextBox5.Text)
                        com.Parameters.AddWithValue("@Password", TextBox6.Text)
                        Dim result As Integer = com.ExecuteNonQuery()
                        If result Then
                            MessageBox.Show("Login successful!")
                            conn.Close()
                        Else
                            MessageBox.Show("The user don't exist")
                        End If
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End Using
    
            End Using
    
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Registerdate()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            LoginDate()
        End Sub
    End Class

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    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.

    Friday, May 5, 2017 8:33 AM
    Moderator