please help me to do with my system.
i want my txtempid.Text is auto generated evrytime i will add new employee .
Field = "emp_id"
i'm using vb 6 as ADODB and Mysql database
thanks in advance...God Bless
please help me to do with my system.
i want my txtempid.Text is auto generated evrytime i will add new employee .
Field = "emp_id"
i'm using vb 6 as ADODB and Mysql database
thanks in advance...God Bless
very simple my friend.
First add a dummy ID in the databse
for eg,
empid empname
1 admin
then before insert find the max(empid)
then add one to it.
and include it in every query you process.
This can be done in frontend.
I am not the one who can help in databse side.
But I am sure that autoincrement is there at mysql I hope.
May be the one who is good at database can help you on that....
Hope this helps you...
Have a happie coding...:=D
Dim rs As Recordset, nextId As Long
Set rs = con.Execute("SELECT Max(emp_id) As LastID FROM theTable")
nextId = 1
If rs.RecordCount <> 0 Then
nextId = rs!LastID
End If
nextId = nextId + 1
@RonalBertogi
why nextId = 1
?
remove 3rd Line.
Because when the table is with no data then nextid will be 2(due to nextId
initialise with 1 and at last incremented by 1) which is not right. it should be 1 when table is empty.
If rs.State = adStateOpen Then rs.Close
rs.Open "select max(emp_id) from tablename", db, adOpenDynamic, adLockReadOnly
If rs(0) <> 0 Then txtempid.Text = rs(0) + 1 Else txtempid.Text = 1
u can also use identity field to auto generate ur field from sql .no need to write code.in sql select field and from properties put identity specification as yes..then it will autogenerate ur field as per ur record
u can also use identity field to auto generate ur field from sql .no need to write code.in sql select field and from properties put identity specification as yes..then it will autogenerate ur field as per ur record
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.