0
      If CbDept_login.Text = "DEPT1" Then
        Dim con As New SqlConnection("Data Source=XYZ-PC;Database=DATABASE1;Integrated Security =true")
        con.Open()
        Dim rs As New SqlCommand("SELECT * FROM TABLE1 WHERE Username=@Username COLLATE SQL_Latin1_General_CP1_CS_AS AND Password=@Password COLLATE SQL_Latin1_General_CP1_CS_AS", con)

        Dim UsernameParam As New SqlParameter("@Username", Me.txtUsername.Text)
        Dim PasswordParam As New SqlParameter("@Password", Me.txtPassword.Text)

        rs.Parameters.Add(UsernameParam)
        rs.Parameters.Add(PasswordParam)


        Dim sqlRead As SqlDataReader = rs.ExecuteReader
        If sqlRead.HasRows Then


            If sqlRead.Read = True Then

                If sqlRead("UserType") = "Admin" Then
                    MsgBox("Log in as " + txtUsername.Text, MsgBoxStyle.OkOnly Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Information, "Login Sucess")
                    frm_Admin.Show()
                    frm_Admin.LblLogAsAdmin_LCR.Text = txtUsername.Text
                    Me.Close()

                ElseIf sqlRead("UserType") = "Staff" Then
                    MsgBox("Log in as " + txtUsername.Text, MsgBoxStyle.OkOnly Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Information, "Login Sucess")
                    frm_User.Show()
                    frm_User.TblogAsuser.Text = txtUsername.Text
                    Me.Close()

                End If

            End If
        Else
            MsgBox("Please input correct username and password", MsgBoxStyle.OkOnly Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical, "Login Failed")

            txtPassword.Text = ""
            con.Close()

        End If
    End If



    If CbDept_login.Text = "DEPT2" Then

        Dim conn As New SqlConnection("Data Source=XYZ-PC;Database=DATABASE2;Integrated Security =true")
        conn.Open()

        Dim rs As New SqlCommand("SELECT * FROM TABLE2 WHERE Username=@Username COLLATE SQL_Latin1_General_CP1_CS_AS AND Password=@Password COLLATE SQL_Latin1_General_CP1_CS_AS", con)

        Dim UsernameParam As New SqlParameter("@Username", Me.txtUsername.Text)
        Dim PasswordParam As New SqlParameter("@Password", Me.txtPassword.Text)

        rs.Parameters.Add(UsernameParam)
        rs.Parameters.Add(PasswordParam)


        Dim sqlRead As SqlDataReader = rs.ExecuteReader
        If sqlRead.HasRows Then


            If sqlRead.Read = True Then

                If sqlRead("UserType") = "Admin" Then
                    MsgBox("Log in as " + txtUsername.Text, MsgBoxStyle.OkOnly Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Information, "Login Sucess")
                    frm_Admin.Show()
                    frm_Admin.LblLogAsAdmin_LCR.Text = txtUsername.Text
                    Me.Close()

                ElseIf sqlRead("UserType") = "Staff" Then
                    MsgBox("Log in as " + txtUsername.Text, MsgBoxStyle.OkOnly Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Information, "Login Sucess")
                    frm_User.Show()
                    frm_User.TblogAsuser.Text = txtUsername.Text
                    Me.Close()

                End If

            End If
        Else
            MsgBox("Please input correct username and password", MsgBoxStyle.OkOnly Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical, "Login Failed")

            txtPassword.Text = ""
            conn.Close()

        End If
    End If
End Sub

Hello, I'm currently facing a problem in my vb project. I'm using visual studio 2012 and SQL server 2012 for my database. I have a login form in which you can access to the different databases just by choosing department name in a combo box and it will check if you input a correct username and password using sqldatareader depends on the username and password value on the database of the department that you choose. Now my problem is when I run it, it will show an error "No source available". maybe my codes are wrong, please help me. thank you in advance. By the way, i put this code on my Login Button.

  • If you set the project to debug mode instead of release mode then you should get a more useful error message which tells you what the problem is and which line of code it happens on. That is the information that we need to be able to help you. – Andrew Morton Oct 03 '17 at 10:42
  • @AndrewMorton I've tried and this is the error "An error occurred creating the form. See Exception.InnerException for details. The error is: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "loginSystem.frm_Login.resources" was correctly embedded or linked into assembly "loginSystem" at compile time, or that all the satellite assemblies required are loadable and fully signed." – Allyni Memes Oct 03 '17 at 10:48
  • 1
    The answers at [Could not find any resources appropriate for the specified culture or the neutral culture](https://stackoverflow.com/q/2058441/1115360) might help. – Andrew Morton Oct 03 '17 at 10:53
  • why have you got multiple DBs, one per dept? Surely just a flag on the relevant user accounts and other items of data (if necessary) to indicate which dept they belong to would be sufficient? Or are the data structures completely different (in which case, perhaps two separate applications would be easier) – ADyson Oct 03 '17 at 11:02

0 Answers0