Hi i have a program in which i want the main form to get information either from the login form or from the sign up form depending on which one is used. Here is the code below. The information does not seem to appear although there is no error. Please help me because i dont know what is wrong.

Imports System.Data.SqlClient

Public Class Home
    Public Acc_no As Integer
    Private password As String

 Private Sub Home_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim conn As New SqlConnection
    Dim rs As SqlDataReader

conn.ConnectionString = ("Data Source=***-PC\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True")
        conn.Open()

        Try



            password = Login.password
            Acc_no = SignUp.Account_no



            Dim com As New SqlCommand

            If password = Login.password Then
                com.CommandText = "Select account_no, First_name, Last_name from Table WHERE pasword = '" & password & "'"
                com.Connection = conn

                rs = com.ExecuteReader

                While rs.Read
                    Me.lblaccno.Text = Convert.ToDouble(rs("account_no"))
                    Me.lblname.Text = Convert.ToString(rs("First_name")) & " " & Convert.ToString(rs("Last_name"))
                    Acc_no = lblaccno.Text
                End While

            ElseIf Acc_no = SignUp.Account_no Then
                com.CommandText = "Select  account_no, First_name, Last_name from Table WHERE account_no ='" & Acc_no & "'"
                com.Connection = conn

                rs = com.ExecuteReader

                While rs.Read
                    Me.lblaccno.Text = Convert.ToDouble(rs("account_no"))
                    Me.lblname.Text = Convert.ToString(rs("First_name")) & " " & Convert.ToString(rs("Last_name"))
                    Acc_no = lblaccno.Text
                End While


            End If
           
        Catch ex As Exception
            MsgBox("ERROR: " & ex.Message.ToString())

        End Try

Recommended Answers

All 3 Replies

Member Avatar for Unhnd_Exception

One thing I see is your setting:

password = Login.password  
Acc_no = SignUp.Account_no

Then you have a If ElseIf Block checking if password = Login.password. Since your setting the password = Login.passord its always going to equal and never make it to the ElseIf section.

Make sure Login.password actually has a value. Set a break point in your code and check it while its running.

Yes it does have a value. What I'm aiming for is that if it it is a new user who begins the program at the sign up page the main form will display their information or if it is a user who has already registered the main form will still get the password entered and display the information. Sort of like a facebk account.

Member Avatar for Unhnd_Exception

I don't use facebook.

If the password has a value and the password is in the table then it should work.

Acc_NO is never going to be reached though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.