Hi Forum,
I need to use an event to a button, here is what i need to do....
- Generate a Random number for a range between 5999 - 9999
- Read the table to make sure the record exists, if it does go back and generate another number until the record doesn't exist so i can added
The button has 3 events?..
Client Before
Server
Client After
Do i generate the number in the Client Before or can i just do everything on the Server
I guess i don't know how to code it. I have the same routine in VB 2008 and works fine but i don't know how to apply it here.
The following is the code that i am using with vb 2008:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Refresh()
' Initialize the random-number generator.
Randomize()
' Generate random value between 5999 and 9999.
Dim value As Integer = CInt(Int((9999 Rnd()) + 5999))
EmployeeIDTextBox.Text = value
' Verify if Employee Number Exists ....
Dim con As New SqlConnection("Data Source=SQLServer;Integrated Security=SSPI;Initial Catalog=Test")
con.Open()
mycommand = New SqlCommand("select count() from Employee where EmployeeID='" & EmployeeIDTextBox.Text & "'")
mycommand.Connection = con
PKExists = mycommand.ExecuteScalar
If (PKExists > 0) Then
MsgBox("Employee Already Exists, Please use Another Number !!!! ")
End If
con.Close()
' Set defaults ....
CurrentFlagTextBox.Text = "1"
UserUpdatedTextBox.Text = My.User.Name
ModifiedDateDateTimePicker.Text = System.DateTime.Today
End Sub
Any suggestions?
Manuel Roman