【VB开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VB开源代码-Ex12_5.frm的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
VERSION 5.00
Begin VB.Form Ex12_5
Caption = "连接Access数据库"
ClientHeight = 3360
ClientLeft = 60
ClientTop = 450
ClientWidth = 3765
LinkTopic = "Form1"
ScaleHeight = 3360
ScaleWidth = 3765
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command4
Caption = "SQL Server OLE DB"
Height = 375
Left = 720
TabIndex = 3
Top = 2280
Width = 1935
End
Begin VB.CommandButton Command3
Caption = "Access OLE DB"
Height = 375
Left = 720
TabIndex = 2
Top = 1680
Width = 1935
End
Begin VB.CommandButton Command2
Caption = "SQL Server ODBC"
Height = 375
Left = 720
TabIndex = 1
Top = 1080
Width = 1935
End
Begin
VB.CommandButton Command1
Caption = "Access ODBC"
Height = 375
Left = 720
TabIndex = 0
Top = 480
Width = 1935
End
End
Attribute VB_Name = "Ex12_5"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim cnn As ADODB.Connection '定义Connection对象
Dim mySQL
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DSN=dbbook" '定义连接字符串
cnn.Open
mySQL = "insert into Oders(orderID,clientID,data) values ('1005','203','2005-5-6')"
cnn.Execute mySQL '执行SQL语句
End Sub
Private Sub Command2_Click()
Dim cnn As ADODB.Connection '定义Connection对象
Dim mySQL
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DSN=Student" '定义连接字符串
cnn.Open
mySQL = "insert into StudentInfo(Sno,Sname,Class,ID) values ('203','刘佳','2','2565702')"
cnn.Execute mySQL '执行SQL语句
End Sub
Private Sub Command3_Click()
Dim cnn As ADODB.Connection '定义Connection对象
Dim mySQL
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\dbbook.mdb;" '定义连接字符串
cnn.Open
mySQL = "insert into Oders(orderID,clientID,data) values ('1006','224','2006-10-15')"
cnn.Execute mySQL '执行SQL语句
End Sub
Private Sub Command4_Click()
Dim cnn As ADODB.Connection '定义Connection对象
Dim mySQL
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI; " & _
" Persist Security Info=False;Initial Catalog=Student; " & _
" Data Source=2NDSPACE-Q9B9UW\SQLEXPRESS;User Id=sa;Pass
word=;" '定义连接字符串
cnn.Open
mySQL = "insert into StudentInfo(Sno,Sname,Class,ID) " & _
" values ('303','袁明蒙','3','3652302')"
cnn.Execute mySQL '执行SQL语句
End Sub