- Код: Выделить всё
Dim conn As New ADODB.Connection
Dim rec As ADODB.Recordset
conn.Open "DRIVER=MySQL ODBC 3.51 Driver;User=" & userid & ";Server=" & serverhostip & ";Database=" & Database & ";Option= 2;Password=" & userpw & ";"
Set rec = conn.Execute("set names 'cp1251'")
Set rec = conn.Execute("select B.id, T.title, IFNULL((Select group_concat(A.name) from authors as A join books_authors as BA on BA.author_id = A.id where BA.book_id = B.id), ''), IFNULL(P.publish, ''), IFNULL(B.year, 0), B.isbn, IFNULL(B.pages, 0), IFNULL(D.department, ''), S.cost, S.quantity from books as B" _
& " JOIN (titles as T cross join store as S) ON (B.title_id=T.id AND S.id=B.id )" _
& " LEFT JOIN (publishers as P cross join departments as D) ON (B.publish_id=P.id AND D.id=S.department_id )" & " " & howselect & "")
With rec
Do While Not .EOF
Set ListObj = ListView1.ListItems.Add(, , .Fields(getcolumn(ListView1.ColumnHeaders.Item(1).Text)))
For i = 1 To Listcol.col - 1
ListObj.SubItems(i) = .Fields(getcolumn(ListView1.ColumnHeaders.Item(i + 1).Text))
If ListObj.SubItems(i) = "0" And ListView1.ColumnHeaders.Item(i + 1).Text <> "Количество" Then ListObj.SubItems(i) = ""
Call getcolor(.Fields(9))
Next i
.MoveNext
Loop
End With
conn.Close