Private Sub Command4_Click()Dim message As StringAdodc1.RecordSource = "select * from employee where eno='" + Trim(Text1.Text) + "'"Adodc1.RefreshOn Error Resume Next'--------------------------------------------------------------If Text1.Text <> Trim(Adodc1.Recordset.Fields("eno")) Thenmessage = MsgBox("不能删除不存在的记录", vbOKCancel, "错误信息")'--------------------------------------------------------------Elsemessage = MsgBox("是否确定要删除表里的记录", vbOKCancel, "确认信息")If message = vbOKCancel ThenDim cn As New ADODB.ConnectionDim com1 As New ADODB.CommandDim rs As New ADODB.RecordsetSet cn = New ADODB.Connectionrs.CursorType = adOpenStaticcn.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.OpenSet rs.ActiveConnection = cnSet com1.ActiveConnection = cncom1.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 IfEnd IfAdodc1.RecordSource = "select * from employee"Adodc1.RefreshEnd Sub我是VB新手,这几天做超市管理系统,这个问题实在想不通,请教高人.两个地方引用一样的原理..为什么上面的可以分流,下面的确只执行 then后的语句.
不是很明白你的意思不過 If message = vbOKCancel Then這個有錯誤了,要麼message=vbOk要麼message=vbCancelmessage = MsgBox("是否确定要删除表里的记录", vbOKCancel, "确认信息")If message = vbOKCancel Then這兩面句可以合成一句if MsgBox("是否确定要删除表里的记录", vbOKCancel, "确认信息")=Vbok thenelseendif
字串4
网友解答:第一个查询要么 Text1.Text = Trim(Adodc1.Recordset.Fields("eno")) ,要么记录集 EOF,语句 Text1.Text <> Trim(Adodc1.Recordset.Fields("eno")) 出错,所以看有没有记录存在只有判断记录集的 EOF 就可以了
字串1
网友解答:谢谢了....tiger的方法可以用原来以为ADO没有EOF.....
字串2
网友解答: