Private Sub Command1_Click ()
Dim conn As New ADODB. Connection
Dim the rs As New ADODB. You
'to connect to the database
Conn. Open "DSN=htt_ODBC"
'open source (i.e., the selected operation data objects)
Rs. Open the "select * from the cutting tool inventory account", conn
MSFlexGrid1. TextMatrix (0, 0)="name"
MSFlexGrid1. TextMatrix (0, 1)="gender", "
MSFlexGrid1. TextMatrix (0, 2)="Chinese"
MSFlexGrid1. TextMatrix (0, 3)="mathematics
"MSFlexGrid1. TextMatrix (0, 4)="English"
'note recordcount property must be in the current record pointer in the final article will return the correct value
Rs. MoveLast
MSFlexGrid1. Rows=rs. RecordCount + 1
MSFlexGrid1. Cols=rs. Fields. The Count
Dim I %
I=1
Rs. MoveFirst
The Do While Not rs. (EOF)
MSFlexGrid1. TextMatrix (I, 0)=rs. Fields (0)
MSFlexGrid1. TextMatrix (I, 1)=rs. The Fields (1)
MSFlexGrid1. TextMatrix (I, 2)=rs. The Fields (2)
MSFlexGrid1. TextMatrix (I, 3)=rs. The Fields (3)
MSFlexGrid1. TextMatrix (I, 4)=rs. Fields (4)
Rs. MoveNext
I=I + 1
Loop
End Sub
CodePudding user response:
Conn. Open " lewd part should be wrong, you can create a database project, and then add a adodc control window, click connctionstring attribute, the installation wizard to help you set up the connection string, and then after the success of the test, copy it outCodePudding user response:
In the "project" - "" reference" menu from the "Microsoft ActiveX Data Objects Library 2.8."CodePudding user response:
Can shows, but the runtime subscript cross-border problems, what might be the problemCodePudding user response:
MSFlexGrid1. Cols=rs. Fields. The Count + 1