by Prashant Barakale (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 14th February 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
New one Using array of fields for inserting data in table
API Declarations
--make connection with table using ADO Data Control
--Place 2 text boxes & set their name property to txtname,txtcity
--Place one button with the name btnInsert
--Syntax --> Array(Fields),Array(Values)
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\table\db1.mdb;Persist Security Info=False"
cn.Open
rs.Open "select * from Details", cn, adOpenDynamic, adLockOptimistic
End Sub
Private Sub btnInsert_Click()
'----we can provide fix values
If rs.BOF = True Then
rs.AddNew Array("name", "city"), Array("Hema Salunke", "Pune")
rs.Update
Else
rs.MoveLast
rs.AddNew Array("name", "city"), Array("Hema Salunke", "Pune")
rs.Update
'--we can also provide control contained value
If rs.BOF = True Then
rs.AddNew Array("name", "city"), Array(txtname, txtcity)
rs.Update
Else
rs.MoveLast
rs.AddNew Array("name", "city"), Array(txtName, txtCity)
rs.Update
End If