hello
I have table in sql server with personnel fields like lastname ,firstname id number e.t.c
In my form on id_number textbox leave event i want to check if the id_number already exists.i'am using the following code :
where textbox=ID_number text
I use the same code for my log in form and it works properlly ..
in my Personnel form does not work and i do not know why..
i need a guideline...thanx in avance
I have table in sql server with personnel fields like lastname ,firstname id number e.t.c
In my form on id_number textbox leave event i want to check if the id_number already exists.i'am using the following code :
VB.NET:
Dim conn As New SqlConnection(My.Settings.MyConnectionString)
Dim text_check = Me.textbox.Text
If conn.State = ConnectionState.Open Then conn.Close()
conn.Open()
Dim cmd As New SqlCommand("SELECT Lastname,Firstname,ID_number FROM Personnel WHERE ID_number = '" & Me.Textbox.Text & "' ", conn)
Dim valid As Boolean = False
Dim HasRows As Boolean = False
Dim IDParam As New SqlParameter("@ID_number", Me.textbox.Text)
cmd.Parameters.Add(IDParam)
Dim dataReader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Try
If dataReader.HasRows Then
While dataReader.Read
If text_check = dataReader.Item("ID_number") Then
valid = True
End If
End While
End If
HasRows = True
dataReader.Close()
Catch exO As SqlException
MessageBox.Show(exO.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If
cmd = Nothing
dataReader = Nothing
conn.Dispose()
End Try
If valid = True Then
Dim msg2 As String
Dim style2 As MsgBoxStyle
Dim title2 As String
Dim result As MsgBoxResult
msg2 = "Current ID_number Already exist"
style2 = MsgBoxStyle.OkOnly
title2 = "Caution"
result = MsgBox(msg2, style2, title2)
If result = MsgBoxResult.Ok Then
Textbox.Text = string.Empty()
textbox.Focus()
End If
End If
I use the same code for my log in form and it works properlly ..
in my Personnel form does not work and i do not know why..
i need a guideline...thanx in avance