【VB开源代码栏目提醒】:网学会员鉴于大家对VB开源代码十分关注,论文会员在此为大家搜集整理了“Ex12_10.frm”一文,供大家参考学习
VERSION 5.00
Begin VB.Form Ex12_10
Caption = "Command对象的使用"
ClientHeight = 3930
ClientLeft = 60
ClientTop = 450
ClientWidth = 7095
LinkTopic = "Form1"
ScaleHeight = 3930
ScaleWidth = 7095
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command4
Caption = "刷新数据显示"
Height = 375
Left = 5400
TabIndex = 4
Top = 2880
Width = 1455
End
Begin VB.CommandButton Command3
Caption = "添加一条记录"
Height = 375
Left = 3720
TabIndex = 3
Top = 2880
Width = 1455
End
Begin VB.CommandButton Command2
Caption = "删除一条记录"
Height = 375
Left = 1920
TabIndex = 2
Top = 2880
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "修改一条记录"
Height = 375
Left = 240
TabIndex = 1
Top = 2880
Width = 1455
End
Begin
VB.PictureBox DataGrid1
Height = 2415
Left = 240
ScaleHeight = 2355
ScaleWidth = 6555
TabIndex = 0
Top = 240
Width = 6615
End
Begin VB.PictureBox Adodc1
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 330
Left = 360
ScaleHeight = 270
ScaleWidth = 6075
TabIndex = 5
Top = 3480
Width = 6135
End
End
Attribute VB_Name = "Ex12_10"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim myConn As New ADODB.Connection
Dim myCmd As New ADODB.Command
'窗体载入事件,初始化Connection对象
Private Sub Form_Load()
Dim mySQL As String
' Set myConn = New ADODB.Connection
mySQL = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=Student;" & _
"Data Source=2NDSPACE-Q9B9UW\SQLEXPRESS;User Id=sa;Pass
word=;"
myConn.ConnectionString = mySQL
myConn.Open
myCmd.ActiveConnection = myConn '建立连接
End Sub
'"修改一条记录"按钮单击事件代码
Private Sub Command1_Click()
Dim mySQL As String
'将是302的学生改成徐明明
mySQL = "update StudentInfo set Sname='徐明明' where Sno='302'"
myCmd.CommandText = mySQL
myCmd.Execute mySQL
End Sub
'"删除一条记录"按钮单击事件代码
Private Sub Command2_Click()
Dim mySQL As String
'将是202的学生信息删除
mySQL = "delete StudentInfo where Sno='202'"
myCmd.CommandText = mySQL
myCmd.Execute mySQL
End Sub
'"添加一条记录"按钮单击事件代码
Private Sub Command3_Click()
Dim mySQL As String
'添加是204的学生信息
mySQL = "insert into StudentInfo values ('204','李丽','2','3610259')"
myCmd.CommandText = mySQL
myCmd.Execute mySQL
End Sub
'"刷新记录显示"按钮单击事件代码
Private Sub Command4_Click()
Adodc1.Refresh
End Sub
'窗体卸载事件代码
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
myConn.Close
Set myConn = Nothing
End Sub