|
数据库用的是sql,有2条记录,但是窗体显示的2条记录是一样的
Private Sub Form_Load()
Dim CNN As Object '定义数据链接对象 ,保存连接数据库信息
Dim rs As ADODB.Recordset '定义记录集对象,保存数据表
Set CNN = CreateObject("ADODB.Connection") '创建数据链接对象
Set rs = CreateObject("ADODB.RecordSet") '创建记录集对象,用于接收数据查询获得的结果集
Dim strCn As String, strSQL As String '链接数据库的字符串变量
'定义本地数据库链接字符串
'strCn = "Provider=sqloledb;Server=本地数据库的名称;Database=数据库名;Integrated Security=SSPI;Persist Security Info=False;"
'定义远程数据库链接字符串
strCn = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=XHP;User ID=sa;Password=lixc223.;Persist Security Info=False;"
CNN.Open strCn
strSQL = "select * from 付款条件表"
rs.Open strSQL, CNN, adOpenKeyset, adLockPessimistic
Set Me.Recordset = rs
Do While Not rs.EOF
Me.Form.Text0 = rs.Fields("ID")
Me.Form.text2 = rs.Fields("合同编号")
rs.MoveNext
Loop
rs.Close
CNN.Close
Set rs = Nothing
Set CNN = Nothing
End Sub
|
|