Axel Richter: An geklontes Recordset Spalten anhängen

Beitrag lesen

Hallo Alexander,

Set rs = CreateObject("ADODB.Recordset")
rs.Fields.Append "Spalte1", adChar, 50 'adChar = 129
rs.Fields.Append "Spalte2", adChar, 50
rs.Open

rs.AddNew
rs("Spalte1").Value = "Dies ist Spalte1.1"
rs("Spalte2").Value = "Dies ist Spalte2.1"

rs.AddNew
rs("Spalte1").Value = "Dies ist Spalte1.2"
rs("Spalte2").Value = "Dies ist Spalte2.2"

RS.Close

rs.Fields.Append "Spalte3", adChar, 50
rs.Fields.Append "Spalte4", adChar, 50

rs.Open

rs.AddNew
rs("Spalte3").Value = "Dies ist Spalte3.1"
rs("Spalte4").Value = "Dies ist Spalte4.1"

rs.AddNew
rs("Spalte3").Value = "Dies ist Spalte3.2"
rs("Spalte4").Value = "Dies ist Spalte4.2"

rs.MoveFirst
While Not rs.EOF
 For i = 0 To rs.Fields.Count-1
   Response.Write RS(i).Name & " - " & RS(i).Value & "<br>"
 Next
 rs.MoveNext
Wend
rs.close
Set rs = Nothing

Ergebnis:
Spalte3 - Dies ist Spalte3.1
Spalte4 - Dies ist Spalte4.1
Spalte3 - Dies ist Spalte3.2
Spalte4 - Dies ist Spalte4.2

Es fehlen also Spalte1 und Spalte2 und 4 Datensätze. Wo sind die hin?
Das kann doch nicht der Sinn von Append sein oder?
Die vorherigen Einträge sind einfach nicht mehr vorhanden - das Recordset wurde aber nicht gelöscht (eigentlich)

Joho. AddNew ohne Update ist wie Wasser in ein Sieb gießen ;-))

http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthaddnew.asp?frame=true

Remarks
Use the AddNew method to create and initialize a new record. Use the Supports method with adAddNew (a CursorOptionEnum value) to verify whether you can add records to the current Recordset object.

After you call the AddNew method, the new record becomes the current record and remains current after you call the Update method. Since the new record is appended to the Recordset, a call to MoveNext following the Update will move past the end of the Recordset, making EOF True. If the Recordset object does not support bookmarks, you may not be able to access the new record once you move to another record. Depending on your cursor type, you may need to call the Requery method to make the new record accessible.

Gruß

Axel