By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,554 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,554 IT Pros & Developers. It's quick & easy.

adding, saving, editing database without adding adodc or datacontrol

P: 55
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.

Expand|Select|Wrap|Line Numbers
  1.  Set rs = New ADODB.Recordset
  2.       Set con = New ADODB.Connection
  3.       con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Program Files\Logsheet\Logsheet.mdb;"
  4.       con.Open
  5.       rs.Open "SELECT * from Employee;", con, adOpenDynamic, adLockOptimistic
  6.        rs.MoveFirst
  7.        Text1.Text = rs.Fields(0)
  8.        Text2.Text = rs.Fields(1)
  9.        Text3.Text = rs.Fields(2)
  10.        Text4.Text = rs.Fields(3)
  11.        Text5.Text = rs.Fields(4)
  12. con.close
  13. rs.close
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2. Set rs = New ADODB.Recordset
  3.       Set con = New ADODB.Connection
  4.       con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Program Files\Logsheet\Logsheet.mdb;"
  5.       con.Open
  6.       rs.Open "SELECT * from Employee;", con, adOpenDynamic, adLockOptimistic
  7.  
  8.        rs.MoveLast
  9.        rs.AddNew
  10.  
  11.  
  12.  
  13. End Sub
  14.  
  15. Private Sub cmdSave_Click()
  16. rs.Update
  17. rs.Close
  18. con.Close
  19. End Sub
Dec 10 '07 #1
Share this Question
Share on Google+
4 Replies


debasisdas
Expert 5K+
P: 8,127
if you want to add a record no need to open the record set.

try this

connction.execute "insert into ................"
Dec 10 '07 #2

P: 55
if you want to add a record no need to open the record set.

try this

connction.execute "insert into ................"
ow i see..
so i just use sql statements for all the functions i want..
tnx :P
Dec 10 '07 #3

debasisdas
Expert 5K+
P: 8,127
For any DML execute the sql statment between the block of begintrans and committrans.

Expand|Select|Wrap|Line Numbers
  1. conn.begintrans
  2. conn.execute "........your DML statment..........."
  3. conn.committrans
Dec 10 '07 #4

Expert 5K+
P: 8,434
Is it just me, or is there a bit of a trend emerging in ilasabba's responses?

Twelve replies so far, and they all say more or less the same thing (apart from typos).
Dec 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.