I am trying to use a Listview1 instead of a datagrid1 by dropping a oledbDataadapter1 or a SQLDataAdapter1 on the Window form But having the hardest time.
I can use this method:

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click

Dim MyConnection As New SqlClient.SqlConnection()
'Define the connection string
MyConnection.ConnectionString = "data Source=localhost;" & _
"Initial Catalog=Northwind;Integrated Security=SSPI"

Dim MySQLString As String
MySQLString = "SELECT fldname1, fldname2, fldname3, fldname4 FROM tables "
"WHERE (Title IN (Select Title FROM table WHERE fldname1 > 0 "
"GROUP BY fldname2Title HAVING COUNT(*) > 1))AND fldname1, > 0 ORDER BY fldname2"


Dim mySelectCommand As New SqlClient.SqlCommand(MySQLString, MyConnection)
'open the connection
Try
mySelectCommand.Connection.Open()
'Assign the listing to a DataReader

Catch ex As Exception
MsgBox(ex.Message)

End Try

Dim myReader As SqlClient.SqlDataReader = mySelectCommand.ExecuteReader()


'Clear out existing item in ListView
ListView1.Items.Clear()

'Read all rows of data
While myReader.Read() = True
Try
'Add Records to the listview
ListView1.Items.Add(myReader.Item("fldname1 "))
ListView1.Items.Item(currentRow).SubItems.Add(myReader.Item("fldname2"))
ListView1.Items.Item(currentRow).SubItems.Add(myReader.Item("fldname3 "))
ListView1.Items.Item(currentRow).SubItems.Add(myReader.Item("fldname4"))

'increment current row counter
currentRow = currentRow + 1
Catch
'handle nulls.

End Try
End While

But using the method of dropping a OledbdataAdapter1 or the sqldataasdapter1 on the form and generate the dataset method is giving me a problem. I don't know how to load the listview1. Field names from the dataset.

Thanks

Data Source=.\SQLEXPRESS;AttachDbFilename=E:\NORTHWIND.MDF;

in connection string add this line. and then see

This article has been dead for over six months. Start a new discussion instead.