I
Ivan Weiss
Okay here is one I cannot figure out. I need to declare an array to
hold the values for a row in my database that I am going to populate a
listview control with.
However, the code is in a class so I can re-use it for any table in my
database so the array length is variable at run time.
How can I declare a variable like this? Currently my code is the
following:
Public Sub fillListView(ByVal argControlForm As Object, ByVal argSql As
String)
Dim myConnection As New OleDbConnection(dbConnString)
Dim myCommand As New OleDbCommand()
Dim myDataReader As OleDbDataReader
Dim myRow() As String
Dim numCols As Integer
Dim i As Integer
With myCommand
.Connection = myConnection
.CommandType = CommandType.Text
.CommandText = argSql
End With
'argControlForm.ListView.clear()
Try
myConnection.Open()
myDataReader = myCommand.ExecuteReader
numCols = myDataReader.FieldCount - 1
While myDataReader.Read
For i = 0 To numCols
myRow(i) = myDataReader.GetString(i)
Next
argControlForm.ListView.Items.Add(New
ListViewItem(myRow))
End While
Catch
DisplayErrorMessage("clsDatabase:fillListView")
Finally
myConnection.Close()
End Try
End Sub
-Ivan
hold the values for a row in my database that I am going to populate a
listview control with.
However, the code is in a class so I can re-use it for any table in my
database so the array length is variable at run time.
How can I declare a variable like this? Currently my code is the
following:
Public Sub fillListView(ByVal argControlForm As Object, ByVal argSql As
String)
Dim myConnection As New OleDbConnection(dbConnString)
Dim myCommand As New OleDbCommand()
Dim myDataReader As OleDbDataReader
Dim myRow() As String
Dim numCols As Integer
Dim i As Integer
With myCommand
.Connection = myConnection
.CommandType = CommandType.Text
.CommandText = argSql
End With
'argControlForm.ListView.clear()
Try
myConnection.Open()
myDataReader = myCommand.ExecuteReader
numCols = myDataReader.FieldCount - 1
While myDataReader.Read
For i = 0 To numCols
myRow(i) = myDataReader.GetString(i)
Next
argControlForm.ListView.Items.Add(New
ListViewItem(myRow))
End While
Catch
DisplayErrorMessage("clsDatabase:fillListView")
Finally
myConnection.Close()
End Try
End Sub
-Ivan