Hi there,
Here I have some code which when called should give me a new event id, the event ids are quite simple C1, C2, C3 etc etc, the database doesn't produce the auto-number part I would like to do this with the code below:
The autonumbers aren't in any partcular order in the database.
So far this code will create an array list of all of the ID's, strip the 'C' part out of the number and sort them but next I need it grab the uppermost one within the array list, is there an easy command to do this?...
Here I have some code which when called should give me a new event id, the event ids are quite simple C1, C2, C3 etc etc, the database doesn't produce the auto-number part I would like to do this with the code below:
The autonumbers aren't in any partcular order in the database.
So far this code will create an array list of all of the ID's, strip the 'C' part out of the number and sort them but next I need it grab the uppermost one within the array list, is there an easy command to do this?...
VB.NET:
Public Sub get_new_event_id()
'open calendar information
'todo move to module call()
Dim connetionString As String
Dim oledbCnn As OleDbConnection
Dim oledbCmd As OleDbCommand
Dim sql As String
Dim arrayListInfo As New ArrayList()
Dim item As String
'todo set password and user for database
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=H:\My Pictures\hotel_db.mdb;User Id=admin;Password=;"
sql = "Select * from tbl_calendar"
oledbCnn = New OleDbConnection(connetionString)
Try
'open and prepare connection
oledbCnn.Open()
oledbCmd = New OleDbCommand(sql, oledbCnn)
Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
Do While oledbReader.Read
'add event id's to an array
item = oledbReader("cal_date_id")
'remvoe the first character C from the ID's in the array
item = item.Remove(0, 1)
'convert to integer
item = Integer.Parse(item)
'add to our array
arrayListInfo.Add(item)
arrayListInfo.Sort()
Loop
[COLOR="Red"]'TODO grab highest value in array[/COLOR]
'convert to string then concatenate C + number
MsgBox("Your number " & item)
oledbReader.Close()
oledbCmd.Dispose()
oledbCnn.Close()
Catch ex As Exception
'get error message
MsgBox(ex.GetType.Name & " : " & ex.Message)
End Try
End Sub
End Class