Hello,
I am using vb6 as front end and oracle as back end. i want to insert new row in database using adodc.
i put adodc1.recordset.addnew on command's click event....do i need to mention adodc1.recorset.save or adodc1.recorset.update?

and while executing the code text boxes are becoming blank whenever i goto next text box..i am unable to find the problem ,i check out rest the connection,service provider part etc..help me out...Thanks for reading...

Dani AI

Generated

Short diagnosis and what likely went wrong (ties to comments from , and ): calling the ADO Data control's Recordset.AddNew makes a new, “current” row in the recordset, but that row is not written to the database until Update is called — and depending on cursor/driver support the new row may not be visible or addressable after a move unless the recordset is requeried. If the form never assigns field values into the new record before Update (or if bound controls are being reset by other code), Update will effectively change the current/visible row instead of creating a distinct new row. (learn.microsoft.com)

Quick checklist to inspect (most common traps):

  • Confirm whether the textboxes are bound (DataSource/DataField) or unbound; bound controls behave differently while AddNew is active.
  • Search form/control events (Change, Exit, LostFocus, Form_Current, ADODC events) for any lines that clear a control (e.g. assignments to TextX.Text) — that is the exact symptom described.
  • Make sure the ADODC.RecordSource is a simple updatable table (not a join or aggregated query) and that the SELECT includes the primary key columns; ADO needs key information to build safe UPDATE/INSERT commands. (learn.microsoft.com)

ADODC / ADO configuration notes (why cursor/lock settings matter): updatability is influenced by CursorType, CursorLocation and LockType (providers do not all support every combination). If the provider cannot supply the required cursor/metadata, ADO may degrade to read-only or construct WHERE clauses that don’t uniquely identify rows. For reliable AddNew/Update behavior set an updatable cursor type and an optimistic lock where the provider supports it — or use a direct SQL INSERT for more deterministic results. (learn.microsoft.com)

Practical alternatives and a safe workflow: rather than relying on ADODC automatic editing, submit a parameterized INSERT using an ADODB Command or Connection.Execute (this avoids ADODC cursor/rowfixup quirks), then call the data-control’s Requery/Refresh so the new row appears in the bound UI. If the database (Oracle) assigns keys via trigger/sequence, a requery is often needed to obtain the generated values in the client cursor. Using explicit INSERT + refresh is the most predictable approach across providers. (learn.microsoft.com)

Recommended Answers

All 4 Replies

if you are saving it to oracle i think u need to create RDO instance not ADO or maybe ADODC works fine....it is the update event that commits the changes to database.

The .update is to follow after the .add, then the data to update and then the .update.

The textboxes clearing its contents has nothing to do with your data connection at all. Post us the code for your add new data and the code currently under the text box. Somewhere there is code that calls the box to be cleared as in

Text1.Text = "" 'or
Text1.Text = vbNullString 'etc

Thanks all..its working fine with .update but its overwriting the single entry in the table again and again so i tried with .movelast still its overwriting...
part of code is -

Private Sub Command1_Click()
Adodc1.Recordset.MoveLast
Adodc1.Recordset.AddNew
'Adodc1.Recordset.Update
End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub

You need some data to add before updating a record. That is why you are getting "overwriting"

Private Sub Command1_Click()
Adodc1.Recordset.MoveLast
Adodc1.Recordset.AddNew
'Add some data here OR if you are using your textboxes, make sure they contain some data.
If Text1.Text = vbNullString Then
   msgBox "Please add data" '...
   Text1.SetFocus
   Exit Sub
      Else
Adodc1.Recordset.Update
End If
End Sub

Secondly, try not to use "" in your code, rather use vbNullString as in -

Private Sub Form_Load()
Text1.Text = vbNullString
Text2.Text = vbNullString
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.