Questo metodo causa un errore di run-time se usato su di un recordset aperto. Il problema è che se lo fai su di uno chiuso è come se non fossi collegato a nessun database, percui hai un recordset in memoria, a cui puoi aggiungere campi, ma che non contiene dati. Ti riporto quanto ho trovato su MSDN Library:
Per poter aggiungere dei campi alle tabelle da VB devi usare le librerie ADOX che permettono l'accesso alla struttura del DB.Calling the fields.Append method for an open Recordset or a Recordset where the ActiveConnection property has been set, will cause a run-time error. You can only append fields to a Recordset that is not open and has not yet been connected to a data source. Typically, these are new Recordset objects that you create with the CreateRecordset method or by explicitly assigning a new Recordset object to an object variable.
Sempre su MSDN Library ho trovato quasto esempio che crea una tabella nel DB NorthWind.mdb e inserisce 3 colonne (fields):
Sub CreateTable()
Dim tbl As New Table
Dim cat As New ADOX.Catalog
'Open the catalog.
' Open the Catalog.
cat.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;"
tbl.Name = "MyTable"
tbl.Columns.Append "Column1", adInteger
tbl.Columns.Append "Column2", adInteger
tbl.Columns.Append "Column3", adVarWChar, 50
cat.Tables.Append tbl
End Sub
Spero ti sia d'aiuto, fammi sapere...
Ciao!!![]()


Rispondi quotando