| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 414 人关注过本帖
标题:[求助]datagrid无法同步显示!
只看楼主 加入收藏
oioc
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-10-17
收藏
 问题点数:0 回复次数:4 
[求助]datagrid无法同步显示!

请教下DataGrid无法同步刷新的问题,见下图。原意是左边点“保存”时插入数据,同时右边刷新datagrid显示刚插入的数据,但在点击运行时,第一次点保存所插入的数据在DataGrid中无法显示,插入第二组数据时才显示第一组数据,依此类推,最后一次点“保存”时的数据无法显示出来。

下面贴上代码,麻烦各位帮忙看下,先谢过了!

Public conn As New ADODB.Connection, rs As New ADODB.Recordset
Public C, DJ, SQLStr, i, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, insertSQL, ReSQL

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{tab}"
End If
End Sub

Private Sub Form_Load()
C = App.Path & "\diamond.mdb"
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & C & ";Persist Security Info=False"
conn.Open
rs.CursorLocation = adUseClient
SQLStr = "select mc from dw where fl='gs'"
rs.Open SQLStr, conn, 3, 1

'combo读入数据库中的数据

If Not rs.BOF Then
For i = 0 To rs.RecordCount - 1
Combo1.AddItem (rs(0).Value)
rs.MoveNext
Next i
End If
rs.Close

SQLStr = "select mc from dw where fl='js'"
rs.Open SQLStr, conn, 3, 1
If Not rs.BOF Then
For i = 0 To rs.RecordCount - 1
Combo2.AddItem (rs(0).Value)
rs.MoveNext
Next i
End If
rs.Close

'预设datagrid的列宽

DataGrid1.Columns(0).Width = 1300
DataGrid1.Columns(1).Width = 1300
DataGrid1.Columns(2).Width = 1300
DataGrid1.Columns(3).Width = 1300
DataGrid1.Columns(4).Width = 1300
DataGrid1.Columns(5).Width = 1300
DataGrid1.Columns(6).Width = 1300
DataGrid1.Columns(7).Width = 1300
DataGrid1.Columns(8).Width = 1300
DataGrid1.Columns(9).Width = 1300
DataGrid1.Columns(10).Width = 1300
DataGrid1.Columns(11).Width = 1300

' DJ是本次插入数据的编号

DJ = "gs" + Format(DDate.Value, "yyyymmdd") + Trim(Left(Right(Now(), 8), 2)) + Trim(Left(Right(Now(), 8), 2)) + Trim(Right(Now(), 2))
ReSQL = "select * from st where djbh='" & DJ & "'"
Adodc1.RecordSource = ReSQL
Adodc1.Refresh
End Sub

Private Sub CmdADD_Click()
If Combo1.Text = "" Or Combo2.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text7.Text = "" Or Text8.Text = "" Then
MsgBox ("输入错误!")
Combo1.SetFocus
Exit Sub
End If
A2 = Trim(DDate.Value)
A3 = Trim(Combo1.Text)
A4 = Trim(Combo2.Text)
A5 = Trim(Text1.Text)
A6 = Trim(Text2.Text)
A7 = Trim(Text3.Text)
A8 = Trim(Text4.Text)
A9 = Trim(Text5.Text)
A10 = Trim(Text6.Text)
A11 = Trim(Text7.Text)
A12 = Trim(Text8.Text)
insertSQL = "insert into st values('" & DJ & "','" & A2 & "','" & A3 & "','" & A4 & "','" & A5 & "','" & A6 & "','" & A7 & "','" & A8 & "','" & A9 & "','" & A10 & "','" & A11 & "','" & A12 & "')"
conn.Execute insertSQL
Combo1.SetFocus
Text1.Text = ""
Text2.Text = "0"
Text3.Text = "0"
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = "0"
Text8.Text = ""
Dim ReFreshSQL As String
ReFreshSQL = "select * from st where djbh='" & DJ & "'"
Adodc1.RecordSource = ReSQL
Adodc1.Refresh
' DataGrid1.Refresh
End Sub
Private Sub CmdExit_Click()
conn.Close
Set conn = Nothing
Unload Me
End Sub
……
下面是判断text文本框的输入是否正确的,略过……
再次感谢!

[此贴子已经被作者于2007-10-13 19:17:55编辑过]

附件: 游客没有浏览附件的权限,请 登录注册
搜索更多相关主题的帖子: datagrid 
2007-10-12 19:58
fcyvhk
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-7-14
收藏
得分:0 
```````````帮顶``路过
2007-10-12 20:16
oioc
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-10-17
收藏
得分:0 
怎么没人过来帮下忙呢?
2007-10-14 13:27
heyufu
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-7-26
收藏
得分:0 
先刷新数据,后读出,试试行不~~~

2007-10-14 13:55
oioc
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-10-17
收藏
得分:0 
以下是引用heyufu在2007-10-14 13:55:00的发言:
先刷新数据,后读出,试试行不~~~

Adodc1.RecordSource = ReSQL
Adodc1.Recordset.Requery
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
先刷新也出不来,还是跟原先一样,只有第2次保存时才能显示第1次插入的数据。谢谢你了。
把Set DataGrid1.DataSource = Adodc1改为Set DataGrid1.DataSource = Adodc1.Recordset也一样

期待高手……

[此贴子已经被作者于2007-10-14 16:51:06编辑过]

2007-10-14 16:47
快速回复:[求助]datagrid无法同步显示!
数据加载中...
 
   



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

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