SHARE
TWEET

Auto Number ID Primary Key Custom Sequence

stevennathaniel Dec 1st, 2015 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.Odbc
  2.  
  3.  
  4. Public Class Form9
  5.  
  6.     Dim koneksi As OdbcConnection
  7.  
  8.     Dim stringKoneksi As String = "DSN=localhost"
  9.  
  10.     Dim stringSQL As String
  11.  
  12.  
  13.     Private Sub Form9_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  14.  
  15.         koneksi = New OdbcConnection(stringKoneksi)
  16.  
  17.         stringSQL = "SELECT * FROM tanggal ORDER BY idtanggal desc"
  18.  
  19.         Dim perintah As New OdbcCommand(stringSQL, koneksi)
  20.  
  21.         Try
  22.  
  23.             koneksi.Open()
  24.  
  25.             Dim baca As OdbcDataReader = perintah.ExecuteReader
  26.  
  27.             baca.Read()
  28.  
  29.             If Not baca.HasRows Then
  30.  
  31.                 TextBox1.Text = "TG" + "0001"
  32.  
  33.             Else
  34.  
  35.                 TextBox1.Text = Val(Microsoft.VisualBasic.Mid(baca.Item("idtanggal").ToString, 4, 3)) + 1
  36.  
  37.                 If Len(TextBox1.Text) = 1 Then
  38.  
  39.                     TextBox1.Text = "TG000" & TextBox1.Text & ""
  40.  
  41.                 ElseIf Len(TextBox1.Text) = 2 Then
  42.  
  43.                     TextBox1.Text = "TG00" & TextBox1.Text & ""
  44.  
  45.                 ElseIf Len(TextBox1.Text) = 3 Then
  46.  
  47.                     TextBox1.Text = "TG0" & TextBox1.Text & ""
  48.  
  49.                 End If
  50.  
  51.             End If
  52.  
  53.         Catch ex As Exception
  54.  
  55.             MessageBox.Show(ex.Message)
  56.  
  57.         End Try
  58.  
  59.     End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top