| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1792 人关注过本帖
标题:datagrid分页出现非空列不能更新为NULL
只看楼主 加入收藏
jshj1982
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-7-12
收藏
 问题点数:0 回复次数:2 
datagrid分页出现非空列不能更新为NULL
代码如下:
Option Explicit

Dim conn As ADODB.Connection

Dim lCurrentPage As Long


Private Sub Command1_Click()
If lCurrentPage > 1 Then

lCurrentPage = lCurrentPage - 1

Call Loadcontrol(lCurrentPage)

End If


End Sub

Private Sub Command2_Click()
lCurrentPage = lCurrentPage + 1

Call Loadcontrol(lCurrentPage)


End Sub

Private Sub Form_Load()
Set conn = New ADODB.Connection

conn.CursorLocation = adUseClient

conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\12.mdb;"

lCurrentPage = 1

Call Loadcontrol(lCurrentPage)


End Sub

Private Sub Loadcontrol(lPage As Long)

Dim adoPrimaryRS As ADODB.Recordset

Dim lPageCount As Long

Dim nPageSize As Integer

Dim lCount As Long

'每页显示的纪录

nPageSize = 10

Set adoPrimaryRS = New ADODB.Recordset

adoPrimaryRS.Open "select * from Sheet1", conn, adOpenStatic, adLockOptimistic

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
End If

objrs.AddNew

objrs!读者编号 = adoPrimaryRS!读者编号

objrs!姓名 = adoPrimaryRS!姓名

objrs!性别 = adoPrimaryRS!性别 ------数据库中此列有空值,已经设置允许为空了,还是不行

adoPrimaryRS.MoveNext

Next

'绑定

Set DataGrid1.DataSource = objrs

'在文本框显示页数

txtPage = lPage & "/" & adoPrimaryRS.PageCount

End Sub

Private Sub Form_Unload(Cancel As Integer)

If Not conn Is Nothing Then

conn.Close

End If

Set conn = Nothing

End Sub

'文本框中输入页数,回车跳转到指定位置

Private Sub txtPage_KeyDown(KeyCode As Integer, Shift As Integer)

lCurrentPage = Val(txtPage.Text)

Call Loadcontrol(lCurrentPage)

End Sub

求高手解决
搜索更多相关主题的帖子: lCurrentPage datagrid NULL Microsoft Sub 
2008-07-14 21:04
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
收藏
得分:0 
adoPrimaryRS!性别換
iif(isnull(adoPrimaryRS!性别),"",adoPrimaryRS!性别)

[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2008-07-15 09:29
快速回复:datagrid分页出现非空列不能更新为NULL
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028573 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved