Private Sub Command2_Click()
DataGrid2.Visible = False
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim r As New ADODB.Recordset
conn.Open "provider=Microsoft.jet.oledb.4.0;data source=" & App.Path & "\trainTime.mdb;persist security info = false"
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Calendar1.Value = "" Then
MsgBox "请输入完整的信息"
GoTo m
Else
sq = "select * from [Ticket],[Train] where Ticket.tno = Train.tno and Ticket.tno = '" & Text1.Text & "' and Fsta = '" & Text2.Text & "' and Lsta = '" & Text3.Text & "' and Dtime= #" & Calendar1.Value & "#"
rs.Open sq, conn, 1, 2
If rs.RecordCount = 0 Then
MsgBox " 无此车票"
GoTo m
rs.Close
Else
rs.Close
sql = "select Train.tno as 车次号,Dtime as 出发日期,Cnum as 座位数量,LastTicket as 剩余票数 from [Ticket],[Train] where Ticket.tno = Train.tno and Ticket.tno = '" & Text1.Text & "' and Fsta = '" & Text2.Text & "' and Lsta = '" & Text3.Text & "' and Dtime= #" & Calendar1.Value & "#"
rs.CursorLocation = adUseClient
rs.Open sql, conn, 1, 2
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
DataGrid1.Visible = True
a = MsgBox("确定购买?", 35, "确认")
If a = vbYes Then
If rs!剩余票数 < 1 Then
MsgBox "此票已售完"
Else
sql = "select * from purchase"
r.Open sql, conn, 1, 2
r.AddNew
r!tno = rs!车次号
r!Dtime = rs!出发日期
rs!剩余票数 = rs!剩余票数 - 1
r!Seat = rs!座位数量 - rs!剩余票数
rs.Update
r.Update
End If
End If
End If
End If
m:
End Sub
Private Sub Command3_Click()
DataGrid1.Visible = False
DataGrid2.Visible = False
End Sub
Private Sub Command4_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
conn.Open "provider=Microsoft.jet.oledb.4.0;data source=" & App.Path & "\trainTime.mdb;persist security info = false"
sql = "select Train.tno as 车次号,Dtime as 出发日期,Ccondition as 有无空调,Fsta as 起始站,Lsta as 终点站,Ftime as 出发时间,Ltime as 到达时间,LastTicket as 剩余票数,Price as 价格 from [Train],[Ticket] where Train.tno= Ticket.tno and Fsta like'%" & Text2.Text & "%' and Lsta like '%" & Text3.Text & "%' and Train.tno like '%" & Text1.Text & "%' and Ttype is not null and Ctype is not null and Ccondition is not null and Fsta is not null and Lsta is not null and Ftime is not null and Ltime is not null and Price is not null and Dtime = #" & Calendar1.Value & "#"
rs.CursorLocation = adUseClient
rs.Open sql, conn, 3, 3
Set DataGrid2.DataSource = rs
DataGrid2.Refresh
DataGrid2.Visible = True
End Sub
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.Open "provider=Microsoft.jet.oledb.4.0;data source=" & App.Path & "\trainTime.mdb;persist security info = false"
Dim dd As Date
dd = Date
sql = "select*from [Ticket] where Dtime <#" & dd & "#"
rs.Open sql, conn, 1, 2
If rs.RecordCount = 0 Then
rs.Close
GoTo m
Else
rs.Close
sql = "select* from [Ticket]"
rs.Open sql, conn, 1, 2
rs.MoveLast
While Not rs.BOF
rs!Dtime = rs!Dtime + 1
rs.MovePrevious
Wend
End If
rs.Close
sql = "select*from [Purchase] where Dtime<#" & dd & "#"
rs.Open sql, conn, 1, 2
If rs.RecordCount = 0 Then
rs.Close
GoTo m
Else
rs.Delete
rs.Update
End If
m:
End Sub
运行起来出现了上述缺少更新或刷新的键列信息,主键没有问题,请问大神们怎么修改?