adding, saving, editing database without adding adodc or datacontrol

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaz215
    New Member
    • Nov 2007
    • 55

    adding, saving, editing database without adding adodc or datacontrol

    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.

    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
    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:
    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
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    if you want to add a record no need to open the record set.

    try this

    connction.execu te "insert into ............... ."

    Comment

    • jaz215
      New Member
      • Nov 2007
      • 55

      #3
      Originally posted by debasisdas
      if you want to add a record no need to open the record set.

      try this

      connction.execu te "insert into ............... ."
      ow i see..
      so i just use sql statements for all the functions i want..
      tnx :P

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        For any DML execute the sql statment between the block of begintrans and committrans.

        [code=vb]
        conn.begintrans
        conn.execute "........yo ur DML statment....... ...."
        conn.committran s[/code]

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          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).
          Last edited by Killer42; Dec 17 '07, 02:39 AM.

          Comment

          Working...