我把信息插入完之后怎么DataGrid里面没显示出来,我把窗口关了,在打开一边才能显示出来
我想插入完数据之后DataGrid里面就能显示出来,下面是我的代码,请帮我看看怎么改才能实现,需要怎么改
Option Explicit
Dim db As Connection
Dim rs As Recordset
Private Sub Command1_Click()
Dim aa(6) As String
Dim conString As String
Dim bb As Double
aa(1) = Trim(Text1.Text)
aa(2) = Trim(Text2.Text)
aa(3) = Trim(Text4.Text)
aa(4) = Trim(Text5.Text)
aa(5) = Trim(Text6.Text)
aa(6) = Trim(Text7.Text)
bb = Val(Text3.Text)
If aa(1) = "" Then
MsgBox "没输入产品名称!", vbExclamation + vbSystemModal, "添加盘店货物单"
Exit Sub
End If
db.Execute ("insert 总库存表(款号,种类,品名,规格,单位,数量,首次入库日期,盘点日期,盘点人,备注)values('" & aa(6) & _
"','" & aa(3) & "','" & aa(1) & "','" & aa(2) & "','" & Combo1 & "','" & bb & _
"','" & DTPicker1 & "','" & DTPicker2 & "','" & aa(4) & "','" & aa(5) & "')")
MsgBox "保存成功!", vbInformation + vbSystemModal, "添加盘店货物单"
'Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim conString As String
DTPicker1 = Date
DTPicker2 = Date
Set db = New Connection
conString = "Provider=SQLOLEDB.1;User ID=sa;Password=;" & _
"DataSource=(local);Database=ZLXT;Persist Security Info=False"
db.ConnectionString = conString
db.Open conString
Set rs = New Recordset
If rs.State <> adStateClosed Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "select * from 总库存表", db, adOpenKeyset, adLockPessimistic
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set db = Nothing
End Sub