主题:datagrid分页后如何对其进行添加删除操作
代码详见附件.
我的思路是在主界面上增加一个TEXT19.TEXT文本框然后在,Loadcontrol在加入以下代码.当你单击增加按钮,使TEXT19.TEXT=1 然后在下面语句中判断如果是1就重新加裁刷新一遍,但是现在是这个方法好像没用.大家帮我看一下,应该怎么改.
Private Sub Loadcontrol(lPage As Long)
Dim lPageCount As Long
Dim nPageSize As Integer
Dim lCount As Long
Dim adoprimaryrs As ADODB.Recordset
Set adoprimaryrs = New ADODB.Recordset
If Text19.Text = 0 Then
If nPageSize < 1 Then nPageSize = 1
adoprimaryrs.PageSize = nPageSize
'每页显示的纪录
nPageSize = 40
adoprimaryrs.Open "select * from featherording", adocon, adOpenStatic, adLockOptimistic
'adoprimaryrs.Open "select * from featherording", adocon, 3, 3
If adoprimaryrs.BOF And adoprimaryrs.EOF Then MsgBox "没有数据记录!", vbExclamation, "没有数据": Exit Sub
adoprimaryrs.PageSize = nPageSize
''页数
lPageCount = adoprimaryrs.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End If
adoprimaryrs.AbsolutePage = lCurrentPage
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 adoprimaryrs.EOF Then Exit For
objrs.AddNew
objrs!Week = adoprimaryrs!Week
'objrs!des = adoprimaryrs!des
objrs!IKEA15EU = adoprimaryrs!IKEA15EU
objrs!IKEA15IT = adoprimaryrs!IKEA15IT
objrs!IKEA15AU = adoprimaryrs!IKEA15AU
objrs!IKEA15JA = adoprimaryrs!IKEA15JA
objrs!IKEA15CN = adoprimaryrs!IKEA15CN
objrs!IKEA6REU = adoprimaryrs!IKEA6REU
objrs!IKEA6RIT = adoprimaryrs!IKEA6RIT
objrs!IKEA6RAU = adoprimaryrs!IKEA6RAU
objrs!IKEA6RJA = adoprimaryrs!IKEA6RJA
objrs!IKEA6RCN = adoprimaryrs!IKEA6RCN
'objrs!qua = adoprimaryrs!qua
'objrs!subdata = adoprimaryrs!subdata
'objrs!buy = adoprimaryrs!buy
adoprimaryrs.MoveNext
Next
''绑定
Set DataGrid1.DataSource = objrs
textpage = lPage & "/" & adoprimaryrs.PageCount
Else
DataGrid1.ClearFields
DataGrid1.ReBind
If nPageSize < 1 Then nPageSize = 1
adoprimaryrs.PageSize = nPageSize
'每页显示的纪录
nPageSize = 40
adoprimaryrs.Open "select * from featherording", adocon, adOpenStatic, adLockOptimistic
'adoprimaryrs.Open "select * from featherording", adocon, 3, 3
If adoprimaryrs.BOF And adoprimaryrs.EOF Then MsgBox "没有数据记录!", vbExclamation, "没有数据": Exit Sub
adoprimaryrs.PageSize = nPageSize
''页数
lPageCount = adoprimaryrs.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End If
adoprimaryrs.AbsolutePage = lCurrentPage
'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 adoprimaryrs.EOF Then Exit For
objrs.AddNew
objrs!Week = adoprimaryrs!Week
'objrs!des = adoprimaryrs!des
objrs!IKEA15EU = adoprimaryrs!IKEA15EU
objrs!IKEA15IT = adoprimaryrs!IKEA15IT
objrs!IKEA15AU = adoprimaryrs!IKEA15AU
objrs!IKEA15JA = adoprimaryrs!IKEA15JA
objrs!IKEA15CN = adoprimaryrs!IKEA15CN
objrs!IKEA6REU = adoprimaryrs!IKEA6REU
objrs!IKEA6RIT = adoprimaryrs!IKEA6RIT
objrs!IKEA6RAU = adoprimaryrs!IKEA6RAU
objrs!IKEA6RJA = adoprimaryrs!IKEA6RJA
objrs!IKEA6RCN = adoprimaryrs!IKEA6RCN
'objrs!qua = adoprimaryrs!qua
'objrs!subdata = adoprimaryrs!subdata
'objrs!buy = adoprimaryrs!buy
adoprimaryrs.MoveNext
Next
''绑定
Set DataGrid1.DataSource = objrs
textpage = lPage & "/" & adoprimaryrs.PageCount
End If
''在文本框显示页数
End Sub
我的思路是在主界面上增加一个TEXT19.TEXT文本框然后在,Loadcontrol在加入以下代码.当你单击增加按钮,使TEXT19.TEXT=1 然后在下面语句中判断如果是1就重新加裁刷新一遍,但是现在是这个方法好像没用.大家帮我看一下,应该怎么改.
Private Sub Loadcontrol(lPage As Long)
Dim lPageCount As Long
Dim nPageSize As Integer
Dim lCount As Long
Dim adoprimaryrs As ADODB.Recordset
Set adoprimaryrs = New ADODB.Recordset
If Text19.Text = 0 Then
If nPageSize < 1 Then nPageSize = 1
adoprimaryrs.PageSize = nPageSize
'每页显示的纪录
nPageSize = 40
adoprimaryrs.Open "select * from featherording", adocon, adOpenStatic, adLockOptimistic
'adoprimaryrs.Open "select * from featherording", adocon, 3, 3
If adoprimaryrs.BOF And adoprimaryrs.EOF Then MsgBox "没有数据记录!", vbExclamation, "没有数据": Exit Sub
adoprimaryrs.PageSize = nPageSize
''页数
lPageCount = adoprimaryrs.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End If
adoprimaryrs.AbsolutePage = lCurrentPage
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 adoprimaryrs.EOF Then Exit For
objrs.AddNew
objrs!Week = adoprimaryrs!Week
'objrs!des = adoprimaryrs!des
objrs!IKEA15EU = adoprimaryrs!IKEA15EU
objrs!IKEA15IT = adoprimaryrs!IKEA15IT
objrs!IKEA15AU = adoprimaryrs!IKEA15AU
objrs!IKEA15JA = adoprimaryrs!IKEA15JA
objrs!IKEA15CN = adoprimaryrs!IKEA15CN
objrs!IKEA6REU = adoprimaryrs!IKEA6REU
objrs!IKEA6RIT = adoprimaryrs!IKEA6RIT
objrs!IKEA6RAU = adoprimaryrs!IKEA6RAU
objrs!IKEA6RJA = adoprimaryrs!IKEA6RJA
objrs!IKEA6RCN = adoprimaryrs!IKEA6RCN
'objrs!qua = adoprimaryrs!qua
'objrs!subdata = adoprimaryrs!subdata
'objrs!buy = adoprimaryrs!buy
adoprimaryrs.MoveNext
Next
''绑定
Set DataGrid1.DataSource = objrs
textpage = lPage & "/" & adoprimaryrs.PageCount
Else
DataGrid1.ClearFields
DataGrid1.ReBind
If nPageSize < 1 Then nPageSize = 1
adoprimaryrs.PageSize = nPageSize
'每页显示的纪录
nPageSize = 40
adoprimaryrs.Open "select * from featherording", adocon, adOpenStatic, adLockOptimistic
'adoprimaryrs.Open "select * from featherording", adocon, 3, 3
If adoprimaryrs.BOF And adoprimaryrs.EOF Then MsgBox "没有数据记录!", vbExclamation, "没有数据": Exit Sub
adoprimaryrs.PageSize = nPageSize
''页数
lPageCount = adoprimaryrs.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End If
adoprimaryrs.AbsolutePage = lCurrentPage
'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 adoprimaryrs.EOF Then Exit For
objrs.AddNew
objrs!Week = adoprimaryrs!Week
'objrs!des = adoprimaryrs!des
objrs!IKEA15EU = adoprimaryrs!IKEA15EU
objrs!IKEA15IT = adoprimaryrs!IKEA15IT
objrs!IKEA15AU = adoprimaryrs!IKEA15AU
objrs!IKEA15JA = adoprimaryrs!IKEA15JA
objrs!IKEA15CN = adoprimaryrs!IKEA15CN
objrs!IKEA6REU = adoprimaryrs!IKEA6REU
objrs!IKEA6RIT = adoprimaryrs!IKEA6RIT
objrs!IKEA6RAU = adoprimaryrs!IKEA6RAU
objrs!IKEA6RJA = adoprimaryrs!IKEA6RJA
objrs!IKEA6RCN = adoprimaryrs!IKEA6RCN
'objrs!qua = adoprimaryrs!qua
'objrs!subdata = adoprimaryrs!subdata
'objrs!buy = adoprimaryrs!buy
adoprimaryrs.MoveNext
Next
''绑定
Set DataGrid1.DataSource = objrs
textpage = lPage & "/" & adoprimaryrs.PageCount
End If
''在文本框显示页数
End Sub