【问题标题】:ListView VB6 and SQL-SERVER, can someone look at my code?ListView VB6 和 SQL-SERVER,有人可以看看我的代码吗?
【发布时间】:2015-11-18 23:25:36
【问题描述】:

我发布了一个问题,要求帮助在 vb6 中使用来自 SQL-SERVER 的数据填充 ListView。所以我能够做到这一点。我正在加载运动的名称,并为每个值分配了 ID。代码如下:

lvwExpenditures.ListItems.Clear
With lvwExpenditures
    .FullRowSelect = True
    .View = lvwReport
    .LabelEdit = lvwManual
    .ColumnHeaders.Add , "FldName", "Expense", 2200
    .ColumnHeaders.Add , "ID", "ID", 0
End With


g_strSQL = "Select FldName, ID, Label, SortOrder from dbo.tblText_References   where fldname ='expenditureitems'"
rs.Open g_strSQL, g_cnDatabase, adOpenStatic
Debug.Print g_strSQL
With rs
  Do While Not .EOF
        Set lvwItem = lvwExpenditures.ListItems.Add(, ,  .Fields("Label").Value)
        lvwItem.SubItems(1) = .Fields("ID").Value 'Populate Date column
     .MoveNext
  Loop
End With
Set rs = Nothing

所以现在,如果用户愿意,我需要让用户从 ListView 中选择多个项目。我用复选框做到了,但我试图在没有它们的情况下做到这一点。此外,如果用户选择多个项目,我的 Insert 语句会是什么样子。我只需要保存与 ID 关联的 ID,并将它们连接起来。谢谢!

【问题讨论】:

    标签: sql-server listview vb6


    【解决方案1】:
    dim g_strSQL as string
    g_strSQL = "SELECT ID, Desc FROM refTest_Insurance Where statuscode = 'a'  ORDER BY InsuranceID ASC"
    Debug.Print g_strSQL
    
    Dim conn As ADODB.Connection
    Dim g_RS As ADODB.Recordset
    
        ' db_file contains the Access database's file name.
        ' Open a connection.
        Set conn = New ADODB.Connection
        conn.ConnectionString = "Your connection string here"
        conn.Open
    
        ' Get the records.
        Set g_RS = conn.Execute(g_strSQL, , adCmdText)
    
        'Set URLs = New Collection
        Do While Not g_RS.EOF
            List1.AddItem g_RS!Desc 
            'URLs.Add CStr(g_RS!Id)
    
            g_RS.MoveNext
        Loop
    
        ' Close the recordset and connection.
        g_RS.Close
        conn.Close
    

    【讨论】:

    • 哪个部分不起作用?你得到一个填充的记录集吗?
    • 是的,我在 SQL-SERVER 中运行查询并看到选择了正确的值。代码卡在 SUBITEMS 上。这是我的代码,抱歉没有注意到你的名字。我以为你指的是我的代码。
    猜你喜欢
    • 2021-10-13
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 1970-01-01
    • 2017-04-22
    相关资源
    最近更新 更多