添加数据后,新纪录不能显示,急!!!
add11窗体添加完数据后,datashow中的数据不能更新,必须要把程序全部的关闭后,再次打开才能显示出刚刚的数据,为什么会这样应该怎么解决?我刚刚开始学VB,有很多不懂的地方,还请各位多多帮忙了。
datashow:
。
Private Sub Loadcontrol(lPage As Long)
If lCurrentPage = 1 Then
cmdPrevious.Enabled = False
first.Enabled = False
End If
If lCurrentPage < adoPrimaryRS.PageCount And lCurrentPage <> 1 Then
cmdPrevious.Enabled = True
first.Enabled = True
cmdNext.Enabled = True
last.Enabled = True
adoPrimaryRS.AbsolutePage = lCurrentPage
End If
If lCurrentPage = adoPrimaryRS.PageCount Then
lPage = adoPrimaryRS.AbsolutePage
adoPrimaryRS.AbsolutePage = adoPrimaryRS.PageCount
cmdNext.Enabled = False
last.Enabled = False
lPage = adoPrimaryRS.PageCount
End If
'定义另一个记录集
Dim objrs As New ADODB.Recordset
'添加字段名称
For lCount = 0 To adoPrimaryRS.Fields.Count - 1
objrs.Fields.Append adoPrimaryRS.Fields(lCount).Name, adVarChar, adoPrimaryRS.Fields(lCount).DefinedSize
Next
'打开记录集
objrs.Open
'将指定记录数循环添加到objrs中
For lCount = 1 To nPageSize
If Not adoPrimaryRS.EOF Then
objrs.AddNew
objrs!编号 = adoPrimaryRS!编号 & " "
objrs!姓名 = adoPrimaryRS!姓名 & " "
objrs!密码 = adoPrimaryRS!密码 & " "
objrs!经验值 = adoPrimaryRS!经验值 & " "
adoPrimaryRS.MoveNext
Else
adoPrimaryRS.MoveFirst
Exit For
End If
Next
Set DataGrid1.DataSource = objrs
add11:
Dim conn As Connection
Dim rs As Recordset
Dim sql As String
Dim db As String
Private Sub Command1_Click()
rs.AddNew
rs!姓名 = T1.Text
rs!密码 = T2.Text
rs!经验值 = T3.Text
rs.Update
Load datashow
datashow.Refresh
datashow.Show
t = MsgBox( "提交成功! ", , "标题 ")
End Sub
Private Sub Form_Load()
Set conn = New Connection
Set rs = New Recordset
db = App.Path + "\net1.mdb "
sql = "select * from ask "
conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;data source= " & db & "; "
rs.Open sql, conn, 1, 3
End Sub
[解决办法]
objrs!经验值 = adoPrimaryRS!经验值 & " "
这里加入一句:objrs.update
adoPrimaryRS.MoveNext