Home > Software engineering >  Vb datalist does not display the data after the data binding
Vb datalist does not display the data after the data binding

Time:11-25

Private Sub Form_Load ()
If cn. State=adStateOpen Then
The Else
Cn. Open the STR
End the If
SQL="select pid, psnname from PSN"
If the rs. State=adStateOpen Then rs. Close
Rs. CursorLocation=adUseClient
Rs. The open SQL, cn, 1, 1
If the rs. BOF=True And rs. EOF=True Then
The Exit Sub
The Else
With DataList1
Set the RowSource=rs
Set the DataSource=rs
. BoundColumn=rs. Fields (0). The Name
. ListField=rs. Fields (1). The Name
End With
If cn. State=adStateOpen Then cn. Close
If the rs. State=adStateOpen Then rs. Close
The Set cn=Nothing
Set the rs=Nothing
End the If
End Sub

CodePudding user response:

Personal experience, don't the whole data binding, all kinds of pit, and the pit to meet is not the beginning,
Suggest write a function, iterate over the data set to control with the data, abundant oneself start work, and have what problem or have what personalized needs also flexible,

CodePudding user response:

Which ace to give directions to be the problem?

CodePudding user response:

reference 1/f, crispy big ice cream reply:
personal experience, don't the whole data binding, all kinds of pit, and the pit to meet is not the beginning,
Advice, write a function to iterate over the data collection of data, to control with the abundant oneself start work, and have what problem or have what personalized needs also flexible,

How to fill in the data, give an example, thank you!

CodePudding user response:

1, apply to the data set
2, to get the data set number of columns
3, the grid set the number of columns and data sets the same number of columns
4, loop to get the data set column head onto the grid
5, to get the data set number of rows
6, the grid lines and lines of the same data sets
7, double loop, line by line, by field to fill in the grid in each grid
8, organizing the grid appearance

CodePudding user response:

Rs. The open SQL, cn, adopenkeyset, adlockreadonly
So try

CodePudding user response:

Don't like to use DataList1 controls, feel more troublesome, use DataGrid1 controls, MSHFlexGrid1 controls, MSFlexGrid1 controls are simple,

Use DataGrid1 control + Adodc1 controls, for example, display the data binding database is particularly simple:
 
Adodc1. The ConnectionString="Provider=Microsoft. Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ database name. MDB. Persist Security Info=False "' binding database connection
Adodc1. RecordSource="Select * From data table name" 'binding set of data table
Adodc1. Refresh
Set DataGrid1.=Adodc1 'DataSource in DataGrid1 controls display data

Only four statements, very simple, isn't it?
If using ADO object can also, of course, but must obtain all record,
  • Related