Results 1 to 3 of 3

Thread: How to auto generate Employee ID from SQL to my VB.NET Application?

  1. #1
    Join Date
    Jan 2009
    Posts
    18

    How to auto generate Employee ID from SQL to my VB.NET Application?

    Hi,

    I want to know how can i auto generate the employee ID from SQL database to my Vb.Net application?

    Please help!

  2. #2
    Join Date
    Feb 2008
    Posts
    1,856

    Re: How to auto generate Employee ID from SQL to my VB.NET Application?

    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();

  3. #3
    Join Date
    May 2008
    Posts
    2,393

    Re: How to auto generate Employee ID from SQL to my VB.NET Application?

    See this following code :

    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
    call that procedure in button click event.
    on button click event...
    AutoEmployeeIDNo()
    end sub

Similar Threads

  1. Auto hang up application
    By TanujC in forum Portable Devices
    Replies: 6
    Last Post: 09-08-2010, 04:24 PM
  2. MP3 Tag Auto Fill Application
    By devrish in forum Windows Software
    Replies: 3
    Last Post: 18-09-2009, 06:40 PM
  3. Auto-Reply to incoming SMS application
    By Dwij in forum Portable Devices
    Replies: 3
    Last Post: 11-05-2009, 12:48 PM
  4. How do i Auto-generate HTML File Index
    By Dharmesh Arora in forum Software Development
    Replies: 2
    Last Post: 23-04-2009, 03:18 PM
  5. How to generate Event log for the Windows Application events
    By Jannat in forum Networking & Security
    Replies: 3
    Last Post: 02-02-2009, 01:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •