hi! how do i add a record in a database without using the datacontrol and adodc. i want to rework my code to using purely codes and not being dependent on the design on vb. so far i have.
and when should i close the connections? i also have cmdbuttons add, edit, save, delete any guide on what to write there?
i have trouble adding a record so i'll just also post it here.
Code:
Set rs = New ADODB.Recordset
Set con = New ADODB.Connection
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Program Files\Logsheet\Logsheet.mdb;"
con.Open
rs.Open "SELECT * from Employee;", con, adOpenDynamic, adLockOptimistic
rs.MoveFirst
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
Text5.Text = rs.Fields(4)
con.close
rs.close
i have trouble adding a record so i'll just also post it here.
Code:
Private Sub cmdAdd_Click()
Set rs = New ADODB.Recordset
Set con = New ADODB.Connection
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Program Files\Logsheet\Logsheet.mdb;"
con.Open
rs.Open "SELECT * from Employee;", con, adOpenDynamic, adLockOptimistic
rs.MoveLast
rs.AddNew
End Sub
Private Sub cmdSave_Click()
rs.Update
rs.Close
con.Close
End Sub
Comment