首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

Adodc1.Recordset 取出空值的BUG解决办法

2012-01-29 
Adodc1.Recordset 取出空值的BUGPrivateSubCommand4_Click()DimmessageAsStringAdodc1.RecordSourcesele

Adodc1.Recordset 取出空值的BUG
Private   Sub   Command4_Click()
Dim   message   As   String
Adodc1.RecordSource   =   "select   *   from   employee   where   eno= ' "   +   Trim(Text1.Text)   +   " ' "
Adodc1.Refresh
On   Error   Resume   Next
'--------------------------
If   Text1.Text   <>   Trim(Adodc1.Recordset.Fields( "eno "))   Then
message   =   MsgBox( "不能删除不存在的记录 ",   vbOKCancel,   "错误信息 ")
'--------------------------
Else
message   =   MsgBox( "是否确定要删除表里的记录 ",   vbOKCancel,   "确认信息 ")
If   message   =   vbOKCancel   Then
Dim   cn   As   New   ADODB.Connection
Dim   com1   As   New   ADODB.Command
Dim   rs   As   New   ADODB.Recordset
Set   cn   =   New   ADODB.Connection
rs.CursorType   =   adOpenStatic
cn.Provider   =   "Microsoft   OLE   DB   Provider   for   SQL   Server "
cn.ConnectionString   =   "Provider=SQLOLEDB.1;Integrated   Security=SSPI;Persist   Security   Info=False;Initial   Catalog=312;Data   Source=CHENLEI "
cn.Open
Set   rs.ActiveConnection   =   cn
Set   com1.ActiveConnection   =   cn
com1.CommandType   =   adCmdText
'com1.CommandText   =   "update   supplier   set   sname= ' "   +   Trim(Text4.Text)   +   " ',coner= ' "   +   Trim(Text5.Text)   +   " ',   tel= ' "   +   Trim(Text6.Text)   +   " '   ,   sid= ' "   +   Trim(Text7.Text)   +   " '   ,   city= ' "   +   Trim(Text8.Text)   +   " '   ,   addr= ' "   +   Trim(Text9.Text)   +   " '   where   sno= ' "   +   Trim(Text3.Text)   +   " ' "
com1.CommandText   =   "delete   from   employee   where   eno= ' "   +   Trim(Text1.Text)   +   " ' "
Set   rs   =   com1.Execute
      Adodc1.RecordSource   =   "select   *   from   employee   where   eno= ' "   +   Trim(Text1.Text)   +   " ' "
      Adodc1.Refresh
'-------------------------
      If   Text1.Text   =   Trim(Adodc1.Recordset.Fields( "eno "))   Then
      massage   =   MsgBox( "该雇员信息被引用,不能删除 ",   vbOKCancel,   "错误信息 ")
      End   If
'---------------------------
End   If
End   If
Adodc1.RecordSource   =   "select   *   from   employee "
Adodc1.Refresh
End   Sub


我是VB新手,这几天做超市管理系统,这个问题实在想不通,请教高人.
两个地方引用一样的原理..为什么上面的可以分流,下面的确只执行   then后的语句.



[解决办法]
不是很明白你的意思

不過 If message = vbOKCancel Then
這個有錯誤了,要麼message=vbOk
要麼message=vbCancel

message = MsgBox( "是否确定要删除表里的记录 ", vbOKCancel, "确认信息 ")


If message = vbOKCancel Then

這兩面句可以合成一句
if MsgBox( "是否确定要删除表里的记录 ", vbOKCancel, "确认信息 ")=Vbok then
else
endif
[解决办法]
第一个查询要么 Text1.Text = Trim(Adodc1.Recordset.Fields( "eno ")) ,要么记录集 EOF,语句 Text1.Text <> Trim(Adodc1.Recordset.Fields( "eno ")) 出错,所以看有没有记录存在只有判断记录集的 EOF 就可以了

热点排行