Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 20-02-2009
Member
 
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!

Reply With Quote
  #2  
Old 20-02-2009
Member
 
Join Date: Feb 2008
Posts: 1,844
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();
Reply With Quote
  #3  
Old 20-02-2009
Member
 
Join Date: May 2008
Posts: 2,379
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
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to auto generate Employee ID from SQL to my VB.NET Application?"
Thread Thread Starter Forum Replies Last Post
Auto hang up application TanujC Portable Devices 6 09-08-2010 04:24 PM
MP3 Tag Auto Fill Application devrish Windows Software 3 18-09-2009 06:40 PM
Auto-Reply to incoming SMS application Dwij Portable Devices 3 11-05-2009 12:48 PM
How do i Auto-generate HTML File Index Dharmesh Arora Software Development 2 23-04-2009 03:18 PM
How to generate Event log for the Windows Application events Jannat Networking & Security 3 02-02-2009 01:47 PM


All times are GMT +5.5. The time now is 01:45 PM.