有一个listview1,有一个adodc1,我现在要把listview1中选中的值,传给一个text1.text,当我text1.text中的值和数据库里的一条记录相等时,我就删除该记录,为什么我不能删除相应的记录,当删除时,总是删除的是listview中的第一条记录帮帮忙!VB新手!

解决方案 »

  1.   

    Private Function get_Comp2()
    Dim dbfix As String
     Dim DBsource As String
     Dim DBtype As String
        
    '  On Error GoTo ERRprocess
     
    dbfix = "Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=B1_R3;Data Source=" & DB_Address  
      With Me.Adodc1
            .CommandTimeout = 30
            .ConnectionString = dbfix
            .CommandType = adCmdText
            .RecordSource = "select * from CUM"        .UserName = DB_User
            .password = DB_Password
            
            .Refresh
      End With
      )
      If Adodc1.Recordset.Fields(Name).Value = Trim(Me.txtr3.Text) Then
      
        Adodc1.Recordset.Delete
      Adodc1.Recordset.Update
      end if
      Exit Function  
    End Function
      

  2.   

    Private Function get_Comp2()
    Dim dbfix As String
     Dim DBsource As String
     Dim DBtype As String
        
    '  On Error GoTo ERRprocess
     
    dbfix = "Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=B1_R3;Data Source=" & DB_Address  
      With Me.Adodc1
            .CommandTimeout = 30
            .ConnectionString = dbfix
            .CommandType = adCmdText
            .RecordSource = "select * from CUM"        .UserName = DB_User
            .password = DB_Password
            
            .Refresh
      End With
      )
    do until Adodc1.Recordset.eof
    If Adodc1.Recordset.Fields(Name).Value = Trim(Me.txtr3.Text) Then
    Adodc1.Recordset.Delete
      Adodc1.Recordset.Update
        exit do
    endif
    Adodc1.Recordset.MoveNext
    loop
      

  3.   

    我不喜欢上面方式,我喜欢用SQL 语句。例:"delete from CUM Where name ='" & txtr3.Text & "'"