I want display data from database in Listbox…Here is my code, It is not working. In Listbox it is displaying as Object[,].Array…..What can i do…
Dim DBCONSRT, QRYSTR As String
Dim strSQL As String
Dim DBCON, myConn, myCommand, rs As Object
Dim NoOfRecords As Long
rs = CreateObject("ADODB.Recordset")
Const DB_CONNECT_STRING = "Provider=MSDASQL.1;Persist Security Info=False;User ID=cpa5k;Data Source=NP1;DSN=NP1;UID=user;PASSWORD=pass;SDSN=Default;HST=ibslnpb1.sysplex.homedepot.com;PRT=4101;Initial Catalog=QA1MM;"
myConn = CreateObject("ADODB.Connection")
myCommand = CreateObject("ADODB.Command")
myConn.Open(DB_CONNECT_STRING)
myCommand.ActiveConnection = myConn
strSQL = "select * from QA1MM.STRSK_OH with ur;"
rs.Open(strSQL, myConn)
ListBox1.Items.Add(rs.GetRows(2))
myConn.Close()
GetRows method is used to retrieve a specified number of rows from a Recordset and to fill an array with the resulting data. so the solution would be to first add the items to an array and then iterate to add the data to the listbox.
For datagrid: