Hi,
I want to know how can i auto generate the employee ID from SQL database to my Vb.Net application?
Please help!
Hi,
I want to know how can i auto generate the employee ID from SQL database to my Vb.Net application?
Please help!
The below piece of code will give you a idea about ID Auto generation.
Here have to select the max value of the id and have to increment it accordingly.
Code:int iJobid = 0; SqlConnection sqlCon = new SqlConnection(""Database=Master;Server=in123;User ID=sa;Password=sa123;"); sqlCon.Open(); SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlCon; sqlCmd.CommandText = "Select Max(EmpID) from EmployeeDetails"; iJobid = (int) sqlCmd.ExecuteScalar(); sqlCon.Close(); if (iJobid > 0) iJobid = iJobid + 1; else iJobid = 1; txtEmpID.Text = iJobid.ToString();
See this following code :
call that procedure in button click event.Code:vb.net Syntax (Toggle Plain Text) 1. Private Sub AutoEmployeeIDNo() 2. Dim myReader As SqlDataReader 3. conn = GetConnect() 4. conn.Open() 5. Dim temp As String 6. Try 7. Dim sql As String = "SELECT MAX(NO) 'EmployeeID' FROM Student " 8. Dim comm As SqlCommand = New SqlCommand(sql, conn) 9. myReader = comm.ExecuteReader 10. If myReader.HasRows Then 11. While myReader.Read() 12. temp = myReader.Item("EmployeeID") + 1 13. End While 14. End If 15. myReader.Close() 16. Catch ex As Exception 17. 18. End Try 19. conn.Close() 20. txtId.Text = String.Concat(temp) ' result will appear in textbox txtId 21. End Sub
on button click event...
AutoEmployeeIDNo()
end sub
Bookmarks