Option Explicit
Private Sub Command1_Click()
Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim conString As String
Dim sql As String
Dim Mart(10, 2) As String
Dim i As Integer, j As Integer
conString = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=admin;"
sql = "Create Table table1(col1 varchar(10),col2 varchar(10))"
Con.Open conString
Con.Execute sql
Randomize
For i = 0 To 9
For j = 0 To 1
Mart(i, j) = CStr(Int(Rnd * 90 + 10))
Next
Next
Rs.Open "select * from table1", Con, adOpenKeyset, adLockPessimistic, adCmdText
For i = 0 To 9
Rs.AddNew
For j = 0 To 1
Rs.Fields(j) = Mart(i, j)
Next
Rs.Update
Next
Rs.Close
Rs.CursorLocation = adUseClient
Rs.Open "select * from table1", Con, adOpenKeyset, adLockReadOnly, adCmdText
While Not Rs.EOF
For i = 0 To Rs.Fields.Count - 1
Print Rs.Fields(i).Value,
Next
Print
Rs.MoveNext
Wend
Rs.Close
Con.Close
Set Rs = Nothing
Set Con = Nothing
End Sub