VB中连接数据库和对数据库进行添加,修改,删除,显示的操作的问题

2024年11月14日 15:16
有2个网友回答
网友(1):

Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\mrlc.mdb" '打开数据库
Data2.DatabaseName = App.Path & "\mrlc.mdb" '打开数据库
End Sub
Private Sub Form_Activate() '系统初始化
Combo1.Text = "产品名称"
Combo2.Text = "like"
Combo3.Text = "产品名称"
Combo4.AddItem ("Asc")
Combo4.AddItem ("Desc")
Combo4.Text = "Asc"
End Sub
Private Sub Command1_Click()
If Check1.Value = 0 Then
If Check2.Value = 0 Then '查询所有数据
Data1.RecordSource = "select * from kc"
Data1.Refresh
End If
If Check2.Value = 1 Then '模糊查询
Data1.RecordSource = "select * from kc where ((kc." & Combo1.Text & " LIKE" + Chr(34) + Text1.Text + "*" + Chr(34) + "))"
Data1.Refresh
End If
End If
If Check1.Value = 1 Then
If Check2.Value = 0 Then '查询所有数据并排序
Data1.RecordSource = "select * from kc order by " & Combo3.Text & " " & Combo4.Text
Data1.Refresh
End If
If Check2.Value = 1 Then '模糊查询并排序
Data1.RecordSource = "select * from kc where ((kc." & Combo1.Text & " LIKE" + Chr(34) + Text1.Text + "*" + Chr(34) + "))order by " & Combo3.Text & " " & Combo4.Text
Data1.Refresh
End If
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub

网友(2):

呜呼