and you're still asking for help yet we are yet to see that code. If you're not going to provide the information we ask for then you make it hard for us to help you.If you're still not sure then please show us the code you're using to authenticate the user at the moment.
Imports System.Data.SqlClient
Public Class frmLogin
Private success As Boolean
Private counter As Byte = 0
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Connect()
Dim cmd As New SqlCommand("Select username,password from table_login where username='" & txtUsername.Text & "'", con)
Dim dr As SqlDataReader = cmd.ExecuteReader
If dr.Read Then
If txtPassword.Text = dr("password") Then
dr.Close()
'success = True
Me.Hide()
frmMenu.Show()
Else
'success = False
counter += 1
MessageBox.Show("Invalid password.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
If counter = 3 Then
Me.Close()
End If
End If
Else
success = False
MessageBox.Show("Username does not exist.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
dr.Close()
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
Public Class frmMenu
Private Sub LoginToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginToolStripMenuItem.Click
frmLogin.ShowDialog()
End Sub
Private Sub RegistrationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegistrationToolStripMenuItem.Click
frmRegistration.MdiParent = Me
frmRegistration.Show()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Disconnect()
Me.Close()
End Sub
Private Sub frmMenu_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim close As String
close = MessageBox.Show("Are you sure you want to exit?", "Exit RCBS", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If close = 7 Then
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
End Class
Firstly, you have to make sure that after adding a toolstrip at your form, you already create an item inside it.
If you want to show some status or other text, then it would be label item.
After that it's easy
If txtPassword.Text = dr("password") Then
dr.Close()
'success = True
frmMenu.toolstrip.items(toolstripstatus).text = textusername.text
Me.Hide()
frmMenu.Show()
Else
'success = False
counter += 1
MessageBox.Show("Invalid password.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
If counter = 3 Then
Me.Close()
End If
End If
Hope this help
could change to:trialer said:VB.NET:Private Sub LoginToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginToolStripMenuItem.Click frmLogin.ShowDialog() End Sub
If frmLogin.ShowDialog() = DialogResult.OK Then
'user name = frmLogin.txtUsername.Text
End If
could change to:
Set the appropriate DialogResult in frmLogin dialog.VB.NET:If frmLogin.ShowDialog() = DialogResult.OK Then 'user name = frmLogin.txtUsername.Text End If
This is how one usually use dialogs.
Imports System.Data.SqlClient
Public Class form_login
Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click
Try
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim rd As SqlDataReader
con.ConnectionString = (connection)
cmd.Connection = con
con.Open()
cmd.CommandText = "SELECT staff_name,staff_pw FROM staff_info WHERE staff_name= (@name) AND staff_pw= (@pw) "
cmd.Parameters.AddWithValue("@name", txt_username.Text)
cmd.Parameters.AddWithValue("@pw", txt_password.Text)
rd = cmd.ExecuteReader
If rd.HasRows Then
Me.Hide()
form_main.ShowDialog()
Else
MessageBox.Show("Invalid Login or Password")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error")
End Try
End Sub
End Class
'-------------------------------------------------------------------------------------------
Public Class form_main
Private Sub form_main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timer.Enabled = True
[B] lblusername.Text = form_login.txt_username.Text[/B]
End Sub
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
nowdatetime.Text = Date.Now.ToString("dd-MM-yyyy hh:mm:ss")
End Sub
End Class
I believe that the Login Information can be show on other Windows Form...
Firstly, i set the 【form_login】 Me.Hide() , information still there....
Secondly, i call the 【form_login】 information to other Windows Form by writing form_login.txt_username.Text
VB.NET:Imports System.Data.SqlClient Public Class form_login Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click Try Dim con As New SqlConnection Dim cmd As New SqlCommand Dim rd As SqlDataReader con.ConnectionString = (connection) cmd.Connection = con con.Open() cmd.CommandText = "SELECT staff_name,staff_pw FROM staff_info WHERE staff_name= (@name) AND staff_pw= (@pw) " cmd.Parameters.AddWithValue("@name", txt_username.Text) cmd.Parameters.AddWithValue("@pw", txt_password.Text) rd = cmd.ExecuteReader If rd.HasRows Then Me.Hide() form_main.ShowDialog() Else MessageBox.Show("Invalid Login or Password") End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error") End Try End Sub End Class '------------------------------------------------------------------------------------------- Public Class form_main Private Sub form_main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load timer.Enabled = True [B] lblusername.Text = form_login.txt_username.Text[/B] End Sub Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick nowdatetime.Text = Date.Now.ToString("dd-MM-yyyy hh:mm:ss") End Sub End Class