本帖最后由 huaxiasky 于 2009-07-11 23:33:21 编辑

解决方案 »

  1.   

    问题一:listview1.Checkboxes=true
    问题二:读listview的第一列与其他的列数有所不同,假设你要读第一列,第二行的话,即listview1.ListItems(2).Text,其中2是行数,如果是读第二行,第四列的话,listview1.ListItems(1).ListSubItems(4).Text,其中1表示第二列,第三列就改成2即可,4表示第四行,如此类推.
    问题三:sql="delete from 表1 where 属性1='" & listview1.SelectedItem.ListSubItems(2).Text & "'"     规则与问题二的一样,如果想选中的话只要把ListItems改成SelectedItem即可注意:如果你不是单选,而是多选的话,那就要加多一个判断,即if listview1.ListItems(i).Checked =true then 即可
      

  2.   

    能不能通过上面给出的条件,帮我做个程序实例出来.谢谢.txtSQL = "select * from userreturn"
    mrc = ExecuteSQL(txtSQL, MsgText)
      

  3.   

    自己写了个代码,不知行不行
    窗体语句
    Option ExplicitPrivate Sub Command1_Click()
        Dim strSql As String
        Dim adoP As ADODB.Recordset
        Dim cnnP As ADODB.Connection
        Dim bolP As Boolean
        Dim strDBPath As String
        Dim strPWD As String
        bolP = funConnectDataBase(cnnP, adoP, strDBPath, strPWD)
        strSql = "Select * From TB"
        Call subExcuteSQL(cnnP, adoP, strSql, True)
        
        If Not adoP.EOF Then
            adoP.MoveFirst
            Do
                '此处添加填写ListView的语句
                '.
                '.
                '.
                adoP.MoveNext
            Loop Until adoP.EOF
        End If
        bolP = funCloseDataBase(cnnP, adoP)
    End Sub模块语句
    Option Explicit
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    '函数功能:连接指定的数据库
    '参数说明:cnnP:数据库连接对象;
    '        :adoP:数据集存储对象;
    '        :strPath:数据库路径;
    '        :strPassword:数据库密码;
    '返回说明:True:连接成功  False:连接失败
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Public Function funConnectDataBase(cnnP As ADODB.Connection, adoP As ADODB.Recordset, ByVal strPath As _
        String, ByVal strPassword As String) As Boolean
    On Error GoTo errFunction
        Set cnnP = New ADODB.Connection
        Set adoP = New ADODB.Recordset
        cnnP.Provider = "Microsoft.Jet.OLEDB.4.0"
        cnnP.Open "Data Source = " & strPath & ";jet oledb:database password=" & strPassword
        funConnectDataBase = True
        Exit Function
    errFunction:
        funConnectDataBase = False
    End Function
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    '函数功能:关闭数据库连接对象和数据文件的关联
    '参数说明:cnnP:数据库连接对象;
    '        :adoP:数据库存储对象;
    '返回说明:True:关闭连接成功  False:关闭连接失败
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Public Function funCloseDataBase(cnnP As ADODB.Connection, adoP As ADODB.Recordset) As Boolean
    On Error GoTo errFunction
        Set adoP = Nothing
        Set cnnP = Nothing
        funCloseDataBase = True
        Exit Function
    errFunction:
        funCloseDataBase = False
    End Function
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    '过程功能:对指定的对象执行指定的SQL语句
    '参数说明:cnnP:ADO连接对象
    '        :adoP:ADO记录集对象
    '        :strSql:SQL语句
    '        :bolQueryRecord:是否是查询记录集
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Public Sub subExcuteSQL(cnnP As ADODB.Connection, adoP As ADODB.Recordset, strSql As String, bolQueryRecord _
        As Boolean)
        If bolQueryRecord Then  '如果是查询记录集
            adoP.Open strSql, cnnP, adOpenStatic, adLockBatchOptimistic
        Else
            cnnP.Execute strSql
        End If
    End Sub
      

  4.   


    'ListView名称为lvw
    '把recordset作为参数传进来,如:
    'call Insert_lvw(myrs),临时写的未测试,可能有点小问题。
    Private Sub Insert_Lvw(rs As ADODB.Recordset)
            Dim i As Long
            Dim ii As Long
            
            With lvw.ColumnHeaders
                For i = 0 To rs.Fields.Count - 1
                    .Add , , rs.Fields.Item(i).Name
                Next
            End With
            With lvw.ListItems
                For i = 0 To rs.RecordCount - 1
                    .Add , , rs(i).Value
                    For ii = 0 To rs.Fields.Count - 1
                        .Item(i + 1).SubItems(ii) = rs(ii).Value
                    Next
                Next
            End With
    End Sub