Private Sub Toolbar2_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As String
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=family.mdb;Persist Security Info=False"
SQL = "select * from OutPutKind where 类型号='" & Text1.Text & "'"
rs.CursorLocation = adUseClient
rs.Open SQL, conn, adOpenKeyset, adLockPessimistic
Select Case Button.Key
Case "delete"
Dim answer As String
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
DataGrid1.AllowDelete = True
rs.Delete
rs.Update
DataGrid1.Refresh
Else
Exit Sub
End If
Case "add"
If Trim(Text1.Text) = "" Then
MsgBox "编号不能为空", vbOKOnly + vbExclamation, ""
ElseIf Trim(Text2.Text) = "" Then
MsgBox "类型不能为空", vbOKOnly + vbExclamation, ""
Else
If rs.EOF Then
rs.AddNew
rs.Fields(0) = Trim(Text1.Text)
rs.Fields(1) = Trim(Text2.Text)
rs.Update
Set DataGrid1.DataSource = rs
MsgBox "添加成功!", vbOKOnly, ""
Text1.Text = ""
Text2.Text = ""
DataGrid1.Refresh
Else
MsgBox "类型号不能相同", vbOKOnly, ""
End If
End If
End Select
End Sub
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As String
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=family.mdb;Persist Security Info=False"
SQL = "select * from OutPutKind where 类型号='" & Text1.Text & "'"
rs.CursorLocation = adUseClient
rs.Open SQL, conn, adOpenKeyset, adLockPessimistic
Select Case Button.Key
Case "delete"
Dim answer As String
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
DataGrid1.AllowDelete = True
rs.Delete
rs.Update
DataGrid1.Refresh
Else
Exit Sub
End If
Case "add"
If Trim(Text1.Text) = "" Then
MsgBox "编号不能为空", vbOKOnly + vbExclamation, ""
ElseIf Trim(Text2.Text) = "" Then
MsgBox "类型不能为空", vbOKOnly + vbExclamation, ""
Else
If rs.EOF Then
rs.AddNew
rs.Fields(0) = Trim(Text1.Text)
rs.Fields(1) = Trim(Text2.Text)
rs.Update
Set DataGrid1.DataSource = rs
MsgBox "添加成功!", vbOKOnly, ""
Text1.Text = ""
Text2.Text = ""
DataGrid1.Refresh
Else
MsgBox "类型号不能相同", vbOKOnly, ""
End If
End If
End Select
End Sub
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As String
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=family.mdb;Persist Security Info=False" Select Case Button.Key
Case "delete"
Dim answer As String
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
conn.Execute "Delete From OutPutKind where 类型号='" & Text2.Text & "'"
ADODC.Recordset.Requery
Else
Exit Sub
End If
Case "add"
If Trim(Text1.Text) = "" Then
MsgBox "编号不能为空", vbOKOnly + vbExclamation, ""
ElseIf Trim(Text2.Text) = "" Then
MsgBox "类型不能为空", vbOKOnly + vbExclamation, ""
Else
SQL = "select * from OutPutKind where 类型号='" & Text2.Text & "'"
Set rs = conn.Execute(SQL)
If rs.EOF
conn.Execute "Insert Into OutPutKind(编号, 类型号) Values('" & Text1.Text & "','" & Text2.Text & "')"
MsgBox "添加成功!", vbOKOnly, ""
Text1.Text = ""
Text2.Text = ""
ADODC.Recordset.Requery
Else
MsgBox "类型号不能相同", vbOKOnly, ""
End If
End If
End Select
End Sub
'修改记录:conn.execute "update tablename set ... where ..."
'删除记录:conn.execute "delete from tablaname where ..."