当前位置:编程学习 > VB >>

adodc不能二次选择删除

求各路高手指教,
代码:
Private Sub Cm_del_Click()

    If MsgBox("要删除该记录吗?", vbYesNo, "信息提示") = vbYes Then
        If Ado_mon.Recordset.RecordCount = 0 Then
                MsgBox "没有可删除记录", vbOKOnly + vbExclamation, "信息提示"
            Else
                Text1.Text = Trim(Ado_mon.Recordset.Fields("no"))
                Adodc1.RecordSource = ""
                Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=stock.mdb;Persist Security Info=False"
                Adodc1.RecordSource = "select * From T_t_in Where T_t_in.no =" & Trim(Ado_mon.Recordset.Fields("no"))
                Adodc1.Refresh
                DataGrid1.Refresh
                Adodc1.Recordset.Delete
                DataG_men.Refresh
                
                Ado_mon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=stock.mdb;Persist Security Info=False"                 '查询输入的单号并显示
                sqltxt3 = "SELECT T_t_in.date, T_t_in.id, T_t_in.y_id, T_t_in.p_name, T_t_in.t_id, T_t_id.t_name, T_t_id.model, T_t_in.num FROM T_t_in INNER JOIN T_t_id ON T_t_in.t_id = T_t_id.t_id where id='" & Tx_id.Text & "'"
                Ado_mon.RecordSource = sqltxt3

                Ado_mon.Refresh
                Sleep 500
                Ado_mon.Refresh

        End If
    End If
End Sub
第一次按的时候,可以正常操作,删除,
第二次选择的时候,Ado_mon.Recordset.RecordCount能找到记录,但
Ado_mon.Recordset.Fields("no")又未找到项目?
搞不懂,请大家来指点指点 --------------------编程问答-------------------- OMG,没有必要的IF嵌套搞得程序神神秘秘.
第一个IF可以改成:
If MsgBox("要删除该记录吗?", vbYesNo, "信息提示") = vbNo Then Exit sub

第二个IF可以改成:
If Ado_mon.Recordset.RecordCount = 0 Then
     MsgBox "没有可删除记录", vbOKOnly + vbExclamation, "信息提示"
     exit sub
end if

后面的SQL语句就不看了,看得蛋疼, 半当中还杀出来个Ado_mon.ConnectionString=XXX
楼主还是用adodb实现吧,MSDN上找个实例好好看看,简单的. --------------------编程问答-------------------- 日,颜色没标上, 楼主忽略上面代码中[color=#FF0000]的标志. --------------------编程问答-------------------- 楼主为什么不定义两个
 sqltxt1= "select * From T_t_in Where T_t_in.no =" & Trim(Ado_mon.Recordset.Fields("no"))
sqltxt2 = "SELECT T_t_in.date, T_t_in.id, T_t_in.y_id, T_t_in.p_name, T_t_in.t_id, T_t_id.t_name, T_t_id.model, T_t_in.num FROM T_t_in INNER JOIN T_t_id ON T_t_in.t_id = T_t_id.t_id where id='" & Tx_id.Text & "'"
按顺序执行就可以,没必要添加两次
Ado_mon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=stock.mdb;Persist Security Info=False"
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,