Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 426

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/templates/ja_purity/ja_templatetools.php on line 49
Auto Increment function in vb.NET - The Scripts Library Community

Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home Visual Basic.NET Auto Increment function in vb.NET

Auto Increment function in vb.NET

E-mail
(1 vote, average: 5.00 out of 5)
This function can be used to get the latest integer key value in a database, and add one to it to insert a new record without duplicated keys. You can put it in a module and call it from anywhere in your application.
If a table has no records in it, it returns 0, then add one to it.
  
Public Function GetID(ByVal TblName As String) As Integer
Dim cn As New db
Dim x As Integer
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = cn.GetConnection ' you can use your own code to connect to the DB
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select max(ID) from " & TblName
cmd.Connection.Open()
x = CInt(IIf(cmd.ExecuteScalar() Is System.DBNull.Value, 0, cmd.ExecuteScalar()))
cmd.Connection.Close()
Return x
End Function


Hope you find it useful.