Display the content selected in the SQL string in ListView

xiaoxiao2021-03-06  68

'[Function]: [Enter]: [Connection ": [Enter]: [Connecting Strings, Whether to display the check box, what is the way to access the database] (Output]: [Database query content Displayed in ListView] '[Parameter]: [Showstr, Passage Call] Private Sub ShowlistView (Byval Showstr As String, Byval Check As Boolean, ByVal DataAccess As String)

If DataAccess = "SQL" TEN '[for SQL Query] DIM SQLCONN AS SQLCLIENT.SQLCONNECTION DIM SQLReader as SqlClient.sqlDataReader Dim Sqlcmd As SqlClient.sqlCommand

Try sqlconn = new sqlclient.sqlconnection (STRCONN) SQLCONN.Open () sqlcmd = new sqlclient.sqlcommand (showstr, sqlconn) sqlreader = sqlcmd.executeReader

'[Add to ListView head title] DIM iHEAD AS INTEGER LISTVIEW1.COLUMNS.CLEAR ()

For iHead = 0 to SQLReader.fieldcount - 1 listview1.columns.add (SqlReader.getname (iHEAD), 100, HorizontalaLight.Center) NEXT

'[Join Each Column] ListView1.Items.clear ()

DIM IROW As Long = 0 DIM IROWHEAD AS INT16

While sqlReader.Read ListView1.Items.Add (sqlReader (0)) For iRowHead = 1 To sqlReader.FieldCount - 1 If (sqlReader (irowhead) Is System.DBNull.value = False) Then ListView1.Items (iRow) .SubItems. Add (CStr (sqlReader (iRowHead))) Else ListView1.Items (irow) .SubItems.Add ( "") End If Next iRow = iRow 1 End While Catch MessageBox.Show (Err.Description, clewInfo, MessageBoxButtons.OK, MessageBoxicon.exclamation) SQLConn.close () exit sub handsqlreader.close () sqlcmd.dispose () SQLCONN.CLOSE ()

Else '[for ole query] DIM OLECONN AS OLEDB.OLDBCONNECONNECTION DIM OLEREADER AS OLEDB.OLEDBDATAREADER DIM OLECMD AS OLEDB.OLEDBCOMMAND

Try oleconn = new oledb.oledbconnection (STRCONN) OLECONN.Open () OLECMD = New Oledb. OleDbcommand (showstr, oleconn) Olereader = Olecmd.executeReader

'[Add to ListView head title] DIM iHEAD AS INTEGER LISTVIEW1.COLUMNS.CLEAR ()

For iHead = 0 to Olereader.fieldcount - 1 listview1.columns.add (Olereader.getname (iHEAD), 100, Horizontalalignment.Center) Next

'[Join Each Column] ListView1.Items.clear ()

DIM IROW As Long = 0 DIM IROWHEAD AS INT16

While oleReader.Read () ListView1.Items.Add (oleReader (0)) For iRowHead = 1 To oleReader.FieldCount - 1 If oleReader (irowhead) Is System.DBNull.value = False Then ListView1.Items (iRow) .SubItems. Add (CStr (oleReader (iRowHead))) Else ListView1.Items (irow) .SubItems.Add ( "") End If Next iRow = iRow 1 End While Catch MessageBox.Show (Err.Description, clewInfo, MessageBoxButtons.OK, MessageBoxicon.exclamation) oleconn.close () exit sub handolereader.close () Olecmd.dispose () oleconn.close ()

END IF

'[Add to the background] DIM I as integer for i = 0 to listview1.items.count - 1 if i mod 2 = 0 Then ListView1.Items (i) .BackColor = Color.lightBlue else ListView1.Items (i) .backcolor = Color.oldlace end if next i

'[Whether to display the Check button] if check = true kilnstview1.checkboxes = true else listview1.checkboxes = false end if End SUB

转载请注明原文地址:https://www.9cbs.com/read-120090.html

New Post(0)