摘要:VB6.0 以下为vb6.0的连接数据库字符串 Dim MyDB As New ADODB.Connection ‘设定MyDB为一个新的ADODB的Connection对象 Dim MyRec As New ADODB.Recordset ‘设定MyRec为一个新的ADODB的Recordset对象 Private Sub C
摘要:VB6.0
以下为vb6.0的连接数据库字符串
Dim MyDB As New ADODB.Connection
‘设定MyDB为一个新的ADODB的Connection对象
Dim MyRec As New ADODB.Recordset
‘设定MyRec为一个新的ADODB的Recordset对象
Private Sub Command1_Click()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:db2.mdb;Persist Security Info=False"
Adodc1.CommandType = adCmdText ‘<--指定为SQL进程
SQL = "Select * From man where 员工编号=‘1‘"
‘一开始的叙述为SQL = "Select * From 文件"
Adodc1.RecordSource = SQL
Adodc1.Refresh ‘<--重新整理
DataGrid1.Refresh ‘<--只秀出符合的数据
End Sub
Private Sub Command2_Click()
‘相关insdelupsata
Dim Cn As Object
Dim Eff As Long
Set Cn = CreateObject("ADODB.Connection")
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:db2.mdb;Persist Security Info=False"
Cn.Execute "DELETE FROM man WHERE 员工编号 = ‘4‘ ", Eff
‘Cn.Execute "INSERT INTO man(员工编号,姓名,名)VALUES() ", Eff
‘Cn.Execute "DELETE FROM man WHERE 员工编号 = ‘4‘ ", Eff
MsgBox "已删除" & Eff & "笔数据"
End Sub
Private Sub Command3_Click()
Text1.Text = Adodc1.Recordset("员工编号")
Text2.Text = Adodc1.Recordset("姓名")
‘
End Sub
Private Sub Command4_Click()
Adodc1.Recordset.Find "员工编号= ‘5‘"
‘字符串函数http://yuan.yocjh.kh.edu.tw/%E6%95%99%E6%9D%90/vb%E5%87%BD%E6%95%B8.htm
End Sub
Private Sub Command5_Click()
MyDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:db2.mdb"
‘ "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:db2.mdb"
‘上面那一行是利用ADODC抄出来的
‘用Microsoft.Jet.OLEDB.3.51这个Provider
‘把数据库载入到MyDB这个ADODB.Connection
‘想要开启Access2000、Access2003的mdb档时,上面要改成:Provider=Microsoft.Jet.OLEDB.4.0;
MyRec.Open "man", MyDB
‘MyRec择开启MyDB里的〝VB网站〞这一个数据表
‘MyRec此时MyRec里以经充满了url.mdb的VB网站的数据了
Do Until MyRec.EOF
List1.AddItem MyRec.Fields(0) & Chr(9) & MyRec.Fields(1) & MyRec.Fields(2)
‘MyRec.Fields(0)是说MyRec指针所在的位置第一栏里的数据
‘MyRec.Fields(1)是说MyRec指针所在的位置第二栏里的数据
‘Chr(9)则是一个跳位符
MyRec.MoveNext
‘MyRec里的指针移到下一笔的位置
Loop
‘如果MyRec的指针已经移到最后一笔,则结束这一个循环
End Sub
原文:大专栏 VB6.0