AUTO Generate PNR or ID by gravi8729

VIEWS: 4 PAGES: 2

More Info
									//AUTO Generate PNR or ID

Public Function GeneratePNRNo() As String

    Dim strMaxPnrNo, strNewPnrNo As String

    Dim intMaxPnrNo, intNewPnrNo As Integer

    Try

     'DBCon.ConnectionString = "provider=sqloledb; data source=HOME-19AFCF4C05; user id=sa;
password=user1; database=userdb;"

     DBCon.ConnectionString = "provider=sqloledb; data source=.; user id=sa;
password=;trusted_connection=yes; database=master;"

      DBCon.Open()




      Dim dsPnrNo As DataSet

      cmd.CommandText = "Select Max(PnrNo) from Passenger"

      DtAdapter.Fill(dsPnrNo)

      If dsPnrNo.Tables(0).Rows(0).Item(0) Is DBNull.Value Then

          strNewPnrNo = "00001"

      Else

          strMaxPnrNo = dsPnrNo.Tables(0).Rows(0).Item(0)

          intMaxPnrNo = CInt(strMaxPnrNo)

          intNewPnrNo = intMaxPnrNo + 1

          Dim i As Integer

          For i = 0 To 5 - Len(CStr(intNewPnrNo)) - 1

             strNewPnrNo &= "0"

          Next

          strNewPnrNo &= intNewPnrNo

      End If

      Return strNewPnrNo
    DBCon.Close()



  Catch ee As Exception

    MsgBox(ee.Message)

  End Try

End Function

								
To top