dear brothers i have a problem in saving ma data in the database.so i need help thanks.

Dani AI

Generated

Common reasons an ADODB save fails: the ADO reference isn't set, the connection string/provider is wrong or not open, SQL or field names are mistyped, data types/lengths mismatch, the DB user lacks INSERT/UPDATE rights, or the code uses a Recordset but never calls the insert/update steps. Check those first.

For a reliable, safe insert use an ADODB Command with parameters (prevents quoting/date issues and SQL injection). Example pattern:

Dim cmd As ADODB.Command
Set cmd = New ADODB.Command

cmd.ActiveConnection = cnn
cmd.CommandType = adCmdText
cmd.CommandText = "INSERT INTO Students (StudentNumber, FirstName, DOB) VALUES (?, ?, ?)"

cmd.Parameters.Append cmd.CreateParameter("pNum", adVarChar, adParamInput, 50, Trim(txtStudentNumber.Text))
cmd.Parameters.Append cmd.CreateParameter("pName", adVarChar, adParamInput, 100, Trim(txtFirstName.Text))
cmd.Parameters.Append cmd.CreateParameter("pDOB", adDate, adParamInput, , CDate(txtDOB.Text))

cmd.Execute

Set cmd = Nothing

Troubleshooting tips and best practices:

  • Ensure "Microsoft ActiveX Data Objects x.x Library" is checked in References.
  • Validate and convert user input before appending parameters (CInt/CDate/Trim).
  • Handle NULLs explicitly if fields allow them.
  • Wrap multiple related operations in a transaction and roll back on error.
  • Close and set objects to Nothing when done.
  • To debug, try the same INSERT in your DB client (or log the parameter values) to isolate ADO vs SQL issues.

Notes tied to earlier replies: ’s recordset approach works for inserts but remember the recordset insert sequence (create a new row, set fields, then save). is correct that executing SQL directly is often simpler for single statements; prefer parameterized commands rather than concatenating strings. ’s nudge to show code is useful — the exact connection string and the SQL you attempted are the most helpful details when narrowing a problem.

Recommended Answers

All 3 Replies

what a problem? post your code friend and show the effort and you will get help from many people here :)

hera a sample code for saving

rec.Open (esql1), conn, adOpenDynamic, adLockOptimistic

rec!StudentNumber = txtSTUDID.Text

rec is your dim on adodb.recordset
conn if for dim on adodb.connection


rec!StudentNumber = txtSTUDID.Text

StudentNumber = the field name

txtSTUDID.text = saving the text inside the textbox


if this is not your prob then kindly post your code
or explain further whats your prob


chao..

if you want to save the data then no need to open the record set at all.

Try using this sample code

'con is the adodb connection object
con.BeginTrans
con.execute "your insert or update statement here."
con.CommitTrans
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.