Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (TextBox1.Text.Trim = "") Then
MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")
TextBox1.Focus()
ElseIf (TextBox2.Text.Trim = "") Then
MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")
TextBox2.Focus()
Else 'if user has not entered a blank space
Try
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Payroll.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "Select * from tbllogin where username = '" & TextBox1.Text & "';"
re = cmd.ExecuteReader()
re.Read()
If TextBox1.Text = re.Item("username") Then
MsgBox("USERNAME ALREADY TAKEN CHOOSE ANOTHER ONE", MsgBoxStyle.Critical)
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
Else
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Payroll.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
cmd.CommandText = "INSERT INTO tbllogin (username,password) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("User Created...Please note down your Username ='" & TextBox1.Text & "' password ='" & TextBox2.Text & "'")
Me.Hide()
Login.Show()
End If
Catch ex As Exception
'Throw
MessageBox.Show(ex.Message)
End Try
re.Close()
con.Close()
End If
End Sub
Getting an Error while Executing Else command I think
Code:
Invalid to read when no data is present
when I click on the button nothing happans and this error message shows up