回 帖 发 新 帖 刷新版面

主题:VB控制ACCESS数据库问题

我最近编了个小程序,需要采用VB界面控制ACCESS数据库,ACCESS数据库内有9张表,但是奇怪的是所有连接方式、读取、修改及添加命令采用相同,只有其中一个表内的数据只能添加、读取而不能修改,另外8张表都能正常实现读取、修改及添加。
敢问大侠们,这有可能是什么问题?
程序运行时没有任何报错
只是在修改数据后点击存储按钮,再打开数据库,原来要修改的那一行没有变化
但是如果向表里添加一行数据的话,点击保存后,查看数据库里面就成功添加了一行数据

Public Sub Command3_Click()’保存按钮 
On Error Resume Next 
adoRS5.MoveFirst 
 
Dim xchoose As VbMsgBoxResult 
Dim i As Integer 
For i = 0 To adoRS5.RecordCount - 1 
On Error Resume Next 
  If adoRS5.Fields("CP-BH").Value = Form1.Text1(3).Text Then 
  xchoose = MsgBox("此产品编号的电压比和移相角数据已经存在,是否覆盖?", 
vbYesNo, "注意") 
  Select Case xchoose 
  Case vbYes 
  Xorsave = False 
   
  Call AdoAdd5 
   
  MsgBox "电压比和移相角数据数据保存完成!"
  Form7.Command1.Enabled = True 
  bc5 = 1 
  Exit Sub 
  Case vbNo 
  Exit Sub 
  End Select 
  Else 
  adoRS5.MoveNext 
   
  End If 
Next 
adoRS5.MoveLast 
 
adoRS5.AddNew 
 
Call AdoAdd5 
MsgBox "电压比和移相角单数据保存完成!"
Form7.Command1.Enabled = True 
bc5 = 1 
 
End Sub 


Public Sub AdoAdd5() '存储实验数据---电压比及移相角测量 
With adoRS5 
   
  If (Form7.Text1(0).Text = "" Or Form7.Text1(0).Visible = False) Then 
  .Fields(0).Value = "/" 
  Else 
  .Fields(0).Value = Form7.Text1(0).Text 
  End If 
   
  .Fields(1).Value = Form7.Combo1.Text 
   
For ii = 1 To 108 
  If (Form7.Text1(ii).Text = "" Or Form7.Text1(ii).Visible = False) Then 
  .Fields(1 + ii).Value = "/" 
  Else 
  .Fields(1 + ii).Value = Form7.Text1(ii).Text 
  End If 
Next 
   
.Fields("CP-BH").Value = Form1.Text1(3).Text 
 
End With 
adoRS5.UpdateBatch adAffectAll 
End Sub 

这是我的修改及添加保存过程。

在建立ACCESS数据库表时,我没有设置任何属性,而且9张表都是一样建立的,只有一样表不能修改,但是可以添加,真是很邪门! 

 

回复列表 (共7个回复)

沙发

看帖必回 这个问题我也想不明白 坐等大神出现..






















signature----------------------------------------------------
O, how bitter a thing it is to look into happiness through another man’s eyes!
[url=http://www.myshox.org/]nike shox clearance[/url]
[url=http://www.myshox.org/shox-nz-c-77.html]nike shox nz[/url]
[url=http://www.myshox.org/nike-shox-r4-c-81.html]nike shox r4[/url]
[url=http://www.myshox.org/nike-shox-clearance-c-70.html]nike shox clearance[/url]

板凳

[quote] 
 If adoRS5.Fields("CP-BH").Value = Form1.Text1(3).Text Then  
    xchoose = MsgBox("此产品编号的电压比和移相角数据已经存在,是否覆盖?",vbYesNo, "注意")

    Select Case xchoose  
           Case vbYes  
                Xorsave = False  
    
                Call AdoAdd5  
    
                MsgBox "电压比和移相角数据数据保存完成!"
                Form7.Command1.Enabled = True  
                bc5 = 1
[color=FF0000]
                Exit Sub  
[/color]           Case vbNo  
[color=FF0000]
                Exit Sub
[/color]
      End Select  
  Else  
      adoRS5.MoveNext  
    
  End If  
[/quote]

两个exit sub  导致你只要第一条产品编号的电压比和移相角数据存在,不管你是否覆盖,程序都退出for循环。

3 楼

Russian President Dmitry Medvedev on Sunday [url=http://www.soccercleatsonlines.com/adidas-soccer-cleats-adidas-adipower-predator-trx-fg-c-1_29.html]adidas Adipower predator[/url] ordered an investigation into the allegations of electoral fraud during last weeks parliamentary vote. The announcement came a day after tens of thousands of people rallied in Moscow and other cities to demand the December 4 polls [url=http://www.cheaptimberlandswholesale.com/]cheap timberlands[/url] won by Prime Minister Vladimir Putins ruling United Russia party be annulled and rerun. In a post on the social media site Facebook, Mr. Medvedev said that although he does not agree with any slogans or speeches made at the rallies, he has given [url=http://www.soccercleatcheap.com/]cheap soccer cleats[/url] instructions to check all information from polling station regarding compliance with the election laws. Within minutes of his statement, Mr. Medvedev had received over 1,000 comments on his Facebook site, most of them angry and some [url=http://www.timberlandoutletonline.com/]timberland outlet online[/url] disrespectful. The Occupy London protest site reached its 60th day Monday, running longer than its counterpart in New York did before it was dismantled. It now occupies three sites across the City of London - a cathedral courtyard, a square [url=http://www.soccercleatsonlines.com/adidas-soccer-cleats-adidas-f50-adizero-micoach-fg-c-1_9.html]adidas adizero f50[/url] and a building. One of the sites even has an art gallery. But with growth has come rivalry between the two, with criticism that some American protesters who have decamped to London from New York are too reliant on their creature [url=http://www.cheaptimberlandswholesale.com/mens-timberland-roll-top-boots-c-3.html]timberland boots on sale[/url] comforts. The U.S. economy has recently showed signs of improvement with the unemployment rate dropping from nine percent to 8.6 percent but it remains far above a normal traditional rate of four or five percent. The jobless rate [url=http://www.soccercleatcheap.com/nike-mercurial-glide-iii-ag-green-black-p-289.html]nike mercurial green[/url] is seen as a major factor in whether Mr. Obama can win re-election to another four-year term next November. The president once again called on Congress to approve his nominee, Richard Cordray, to head a new consumer [url=http://www.timberlandoutletonline.com/mens-timberland-roll-top-boots-wheat-p-50.html]timberland roll top boots[/url] protection agency. U.S. President Barack Obama is pressing Republicans in Congress to approve his nominee Richard Cordray to head the first ever consumer guardian agency. During his weekly address Saturday, Obama urged lawmakers to give [url=http://www.soccercleatsonlines.com/nike-soccer-cleats-nike-mercurial-vapor-viii-fg-c-41_64.html]nike mercurial vapor fg[/url] Americans the protection they need from being taken advantage of by mortgage lenders, payday lenders and debt collectors. The president says many people on Wall Street have made a lot money taking advantage of consumers. He is appealing [url=http://www.cheaptimberlandswholesale.com/]timberland for sale[/url] to legislators to give Americans an advocate he says will protect them from unscrupulous practices. Protesters came out across the worlds largest country to demand clean elections and to say what, only one week ago, [url=http://www.soccercleatcheap.com/nike-soccer-cleats-nike-mercurial-victory-iv-ag-c-41_73.html]nike mercurial victory iv[/url] was unsayable. Russia Without Putin was the favorite chant of thousands of demonstrators who marched within earshot of the Kremlin in the largest pro-democracy demonstration since Vladimir Putin came to power in 2000. From Vladivostok on the Pacific [url=http://www.timberlandoutletonline.com/mens-timberland-6-inch-premium-boots-olive-green-p-112.html]timberland boots for men[/url] Coast to Kaliningrad on the Baltic.CF

4 楼

楼主应该毫不手软的结贴,慷慨激昂的给分

5 楼

我猜,本问题没有解决,至少在本帖里没有。
因为源代码中,在选择覆盖后执行了
Call AdoAdd5
才exit的。
估计是他的AdoAdd5过程为其他设计,后来想公用,而一些使用细节未调整。
同样的,本楼楼主没有再来看帖子是否有回复。

结论:
1、学会设置断点调试,是排除逻辑错误的必备手段;
2、专家分为0的人发的问题贴,有80%的可能不会再回来看,所以回答的时候要有心理准备。

6 楼

[quote]我猜,本问题没有解决,至少在本帖里没有。
因为源代码中,在选择覆盖后执行了
Call AdoAdd5
才exit的。
估计是他的AdoAdd5过程为其他设计,后来想公用,而一些使用细节未调整。
同样的,本楼楼主没有再来看帖子是否有回复。

结论:
1、学会设置断点调试,是排除逻辑错误的必备手段;
2、专家分为0的人发的问题贴,有80%的可能不会再回来看,所以回答的时候要有心理准备。[/quote]
这个问题,其实来说很简单。让那个同志养成良好的习惯:
1、启动程序的时候开始连接数据库,conn连接
2、每一个具体的过程或者函数,或者要完成的任务,使用一个recordset,而且在每次使用完了后在关闭。且不可以一进程序就开一个recordset,然后close的语句到处乱放。这样很容易导致因为程序走向的不可控而导致连接出现错误。无法访问记录集,或者无法添加数据。

7 楼

我说的核心意思是,楼主的专家分为0;楼主提问以后根本就没有对我们这样自作多情环的人的情谊加以理会——根本没有来看大家说了啥。所以按那谁的建议,专家分为零的人都是一次性的,可以不必理会。

我来回复

您尚未登录,请登录后再回复。点此登录或注册